UVa-10341
題意:解方程
p*e-x?+?q*sin(x) +?r*cos(x) +?s*tan(x) +?t*x2?+?u?= 0
????????where?0 <=?x?<= 1.(0 <=?p,r?<= 20?and?-20 <=?q,s,t?<= 0)
題目鏈接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=493&problem=1282
觀察可得 求導可得此函數是遞減函數 判斷是否有解即 f(0) * f(1) <= 0
在此還要懂得運用 三角函數 ,還有求e^(-x) ,要用到exp函數求解 e^(-x) = exp(-x);
三角函數sin(x) 中x指的經過角度變化的弧度
解決此題用二分求解
#include<stdio.h> #include<math.h> double p,q,r,s,t,u; double f(double x) {return p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u ; } void find(double x,double y) {double mid;while(y - x > 0.000000001){mid =( x + y ) / 2 ;double t = f(mid) ;if(t < 0) y = mid;else x = mid ;}printf("%.4lf\n",mid); } int main() {while(scanf("%lf%lf%lf%lf%lf%lf",&p,&q,&r,&s,&t,&u)!=EOF){if(f(0) * f(1) > 0) printf("No solution\n");else{find(0.0,1.0);}} }
總結
- 上一篇: “彪悍人生”罗永浩被法院限制消费,网友:
- 下一篇: 少走弯路,给3~5年程序员的唯一一条建议