您的位置:首页 > 其它

Can you solve this equation?---hdu2199(二分)

2015-09-04 13:56 330 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2199

给出y的值求x;

8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 = Y

x是0到100的实数所以要用二分的方法;

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
#define N 110
#define INF 0xffffff

int main()
{
int T,flag;
double y, m, L, R, Mid;
scanf("%d", &T);
while(T--)
{
scanf("%lf", &y);
m=8*pow(100,4)+7*pow(100,3)+2*pow(100,2)+3*100+6;
if(m<y||y<6)
{
printf("No solution!\n");
continue;
}
L=0;R=100;
while(L<=R)
{
Mid=(L+R)/2;
m=8*pow(Mid,4)+7*pow(Mid,3)+2*pow(Mid,2)+3*Mid+6;
if(fabs(m-y)<0.0001)
{
flag=1;
break;
}
else if(m>y)
{
R=Mid;
}
else
{
L=Mid;
}
}
if(flag==1)
printf("%.4lf\n", Mid);
else
printf("No solution!\n");
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: