首页 > 代码库 > UVA - 10341-Solve It
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。