首页 > 其他 > 详细

hdu 2199 Can you solve this equation

时间:2015-04-09 19:47:38      阅读:241      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!