8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y 求这个方程在(0,100)的解
二分(0,100) 每次求出8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 的值
如果Y小于6或者大于x=100时Y的值直接 输出 No solution!
若比Y大 减小x 否则增大x
#include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include <math.h> #include <map> #include <string> #include <set> #include <stack> #include <queue> using namespace std; #define forseach(i,j,n) for(int i=j;i<n;i++) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //#define PI acos(-1) typedef long long ll; //const int maxn = 1e9; int main() { //debug; //ios; double l,r,Y,ans,mid; double sh=8*pow(100,4)+7*pow(100,3)+2*pow(100,2)+3*100+6; int T; cin>>T; while(T--) { cin>>Y; if(Y<6||Y>=sh) { cout<<"No solution!"<<endl; continue; } if(Y==6) { cout<<"0.0000"<<endl; continue; } l=0,r=100,ans=0; while(abs(ans-Y)>0.0001) { mid=(l+r)/2; ans=8*pow(mid,4)+7*pow(mid,3)+2*pow(mid,2)+3*mid+6; if(ans>Y) { r=mid-1; } else { l=mid+1; } } printf("%.4f\n",mid); } return 0; }