HDU 2199 Can you solve this equation?
题解:二分求解
#include <cstdio> #include <cmath> using namespace std; double f(double x) { return(8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6); } int main() { int t; double l,r,mid,yl,yr,y,y1; scanf("%d", &t); while(t--) { l=0; r=100; scanf("%lf",&y1); yl=f(l)-y1; yr=f(r)-y1; if (yl>0||yr<0) printf("No solution!\n"); else{ while (fabs(l-r)>=0.000000001) { mid=(l+r)/2; y=f(mid)-y1; if (y>=0) r=mid; else l=mid; } printf("%0.4lf\n",mid); } } return 0; }
愿你出走半生,归来仍是少年