主要思想就是两端逼近,最后得到结果,0MS
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const double ep = 1e-6; double deal(double n) { return 8*pow(n,4) + 7*pow(n,3) + 2*pow(n,2) + 3*n + 6; } int main() { int t,i; double y; scanf("%d",&t); while (t--) { scanf("%lf",&y); double lo = 0,hi = 100; if(y<deal(0) || y>deal(100)) { printf("No solution! "); continue; } else { double mid; while(hi-lo>ep) { mid = (lo+hi)/2; if(deal(mid)>y) { hi = mid; } else { lo = mid; } } printf("%.4lf ",hi); } } return 0; }