码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 2199 Can you solve this equation

时间:2015-04-09 19:49:13      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

心情不好,简单的二分

#include<iostream>
#include<cstdio>
#include<cmath> 
using namespace std;
double y;
int cal(double x)
{
	return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
}
double find()
{
	double mid;
	double a,b;
	a=0;b=100;
	while(b-a>1e-8)
	{
		mid=(a+b)/2;
		if(cal(mid)<y) a=mid;
		else
		b=mid;
	}
	return (a+b)/2.0;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>y;
		if(cal(0)<=y&&y<=cal(100)) printf("%.4f\n",find());
		else cout<<"No solution!"<<endl;
	}
	return 0;
}


hdu 2199 Can you solve this equation

标签:

原文地址:http://blog.csdn.net/zafkiel_nightmare/article/details/44964279

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!