UVA - 10341-Solve It

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA - 10341-Solve It相关的知识,希望对你有一定的参考价值。

10341 - Solve It

Time limit: 3.000 seconds 

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 ?le.
Output
For each set of input, there should be a line containing the value of x, correct up to 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

 

题意就是解方程。。。

二分

代码:

#include<stdio.h>
#include<math.h>
#define eps 0.0000001
int p,q,r,s,t,u;
double fun(double x){
    double y;
    y=p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
    return y;
}
int main()
{
    while(scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u)!=EOF)
    {
        double maxx=1.0,minn=0.0,mid;
        if(fun(maxx)*fun(minn)>0){
            printf("No solution\n");
            continue;
        }
          while(minn+eps<maxx){
                    mid=(maxx+minn)/2.0;
            if(fun(mid)<=0)
                maxx=mid;
            else
                minn=mid;
          }
          printf("%.4f\n",mid);
    }
    return 0;
}

 

以上是关于UVA - 10341-Solve It的主要内容,如果未能解决你的问题,请参考以下文章

UVA 10341 Solve It

UVA 1514 Piece it together (二分图匹配)

例题 8-13 UVA - 11093Just Finish it up

UVA11093-Just Finish it up(思维)

UVa658 It's not a Bug, it's a Feature! (最短路,隐式图搜索)

uva658 It's not a Bug, it's a Feature!