标签:
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <map> #define ms(a) memset(a,0,sizeof(a)) #define msp memset(mp,0,sizeof(mp)) #define msv memset(vis,0,sizeof(vis)) using namespace std; #define LOCAL int y; double fun(double x) { return 8*pow(x,4.0)+7*pow(x,3.0)+2*pow(x,2.0)+3*x+6; } void solve() { if(fun(0)>y||fun(100)<y) { printf("No solution!\n"); return; } double a=0,b=100,ans,m; while(b-a>1e-6) { m=(a+b)/2; ans=fun(m); if(ans>y)b=m-1e-7; else a=m+1e-7; } m=(a+b)/2.0; printf("%.4lf\n",m); return; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL //Start int N; cin>>N; while(N--) { cin>>y; solve(); } return 0; }
HDU 2199 Can you solve this equation?(二分搜索)
标签:
原文地址:http://www.cnblogs.com/gpsx/p/5167638.html