ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

Can you solve this equation?

Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
Now,given the equation *x^ + *x^ + *x^ + *x + == Y,can you find its solution between and ;
Now please try your lucky. Input
The first line of the input contains an integer T(<=T<=) which means the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y) <= 1e10); Output
For each test case, you should just output one real number(accurate up to decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between and . Sample Input - Sample Output
1.6152
No solution! Author
Redow Recommend
lcy

数学题,直接二分,代码

 #include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"
#include"cmath"
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define MX 10000 + 50
using namespace std; double f(double x)
{
return *pow(x,)+*pow(x,)+*pow(x,)+*x+;
} int main()
{
int n;
double m;
while(~scanf("%d",&n))
{
for(int k=; k<=n; k++)
{
scanf("%lf",&m); double i=0.0;
if(m<f()||m>f())
{
printf("No solution!\n");continue;
}
double fr=0.0,ed=100.0;
for(; fabs(f(fr)-f(ed))>1e-;)
{
i=(fr+ed)/;
if(f(i)<m)fr=i;
else ed=i;
}
{
printf("%.4lf\n",i);
}
}
}
return ;
}
上一篇:关于hexo博客自定义域名后gitment评论系统登陆出现redirect error返回主页的解决办法


下一篇:DatePickerDialog、AutoCompleteTextView