枚举二分hdu2199

版权声明:本文为博主原创文章,未经博主允许也可以转载。 https://blog.csdn.net/FrankAx/article/details/74236238
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <math.h>
#define INF  1e-6
#define MIN 1e-7
using namespace std;
int p,q;
double fun(double x){
  return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
}
int main()
{
	int Y;
	int T;
	cin>>T;
	while(T--){
		cin>>Y;
		double l = 1;
		double r = 100;
		double mid;
	 	if(fun(1)>Y || fun(100)<Y){
	 		cout<<"No solution!"<<endl;
	 	}else{
	 		mid = (double)(l+r)/2.0;
	 		while(r-l>INF){		
			  
			if(fun(mid)<Y){
				l = mid + MIN;
			}else if(fun(mid)>Y){
				r = mid - MIN;	
			}		
			mid = (double)(l+r)/2.0;
		}
		printf("%.4lf\n",(double)(l+r)/2.0);
	 	}
	}
	return 0;
}
展开阅读全文

没有更多推荐了,返回首页