现在的位置: 首页 > 综合 > 正文

UVA – 10341 Solve It

2019年11月08日 ⁄ 综合 ⁄ 共 1883字 ⁄ 字号 评论关闭
文章目录

二分......精度开大点....递减的.....

学会了exp()函数.....求e的n次方的.........

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-9;
double p, q, r, s, t, u;
double gety(double x)
{
    return p*exp(-x)+ q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u;
}
int main()
{
    //freopen("in","r",stdin);
    double low,high,mid;
    while(cin>>p>>q>>r>>s>>t>>u)
    {
        if(gety(0)<0||gety(1)>0)
        {
            cout<<"No solution"<<endl;
            continue;
        }
        low=0;high=1;
        while(high-low>eps)
        {
            mid=(high+low)/2;
            if(gety(mid)>0)
                low=mid;
            else
                high=mid;
        }
        printf("%.4f\n",mid);
    }
    return 0;
}

UVA - 10341

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

Submit

Status

Description

Download as PDF

Problem F

Solve It

Input: standard input

Output: standard output

Time Limit: 1 second

Memory Limit: 32 MB

Solve the equation:
        p*e-x+ q*sin(x) + r*cos(x) +
s*tan(x) + t*x2 + u = 0
        where 0 <= x <= 1.

Input

Input consists of multiple test cases and terminated by an EOF. Each test case consists of 6 integers in a single line:
p, q, r, s, t and u (where 0 <=
p,r <= 20 and -20 <= q,s,t <= 0). There will be maximum 2100 lines in the input file.

Output

For each set of input, there should be a line containing the value of x, correct upto 4 decimal places, or the string "No solution", whichever is applicable.

Sample Input

0 0 0 0 -2 1
1 0 0 0 -1 2
1 -1 1 -1 -1 1

Sample Output

0.7071
No solution
0.7554

Mustaq Ahmed

Source

Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 3. Problem Solving Paradigms ::

Divide and Conquer

Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) ::
Volume 4. Algorithm Design

Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Problem Solving Paradigms ::

Divide and Conquer -Binary Search

Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 1. Introduction ::

Preview Contest

Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Problem Solving Paradigms :: Divide and Conquer ::

Binary Search the Answer

Root :: Prominent Problemsetters ::
Mustaq Ahmed

抱歉!评论已关闭.