标签:
题目链接 http://acm.hust.edu.cn/vjudge/problem/19047
解题思路
方程左边为单调函数。二分。
代码
#include<stdio.h> #include<math.h> #define MIN 1e-10 //#define LOCAL double p, q, r, s, t, u; double fun(double x) { return p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u; } int main() { #ifdef LOCAL freopen("data.txt", "r", stdin); freopen("ans.txt", "w", stdout); #endif double x=0.0, y=1.0; double ans, mid; while(scanf("%lf%lf%lf%lf%lf%lf", &p, &q, &r, &s, &t, &u)==6) { if(fun(0.0)*fun(1.0)>0) { printf("No solution\n"); continue; } else while(fabs(y-x)>MIN) { mid = x+(y-x)/2.0; ans = fun(mid); if(ans<0) y = mid; else x = mid; } printf("%.4lf\n", x); x = 0.0; y=1.0; } return 0; }
标签:
原文地址:http://www.cnblogs.com/ZengWangli/p/5778656.html