HDU-2199-Can you solve this equation?

简介: HDU-2199-Can you solve this equation?

Can you solve this equation?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13001    Accepted Submission(s): 5823


Problem Description

Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;

Now please try your lucky.

 


Input

The first line of the input contains an integer T(1<=T<=100) 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 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.

 


Sample Input

      2 100 -4      

 


Sample Output

      1.6152 No solution!      



题目与分析:纯粹的二分法求解问题,此题注意精度控制就行了  1e-8 就是科学计数法  先当于 1*10 的 -8 次方也就是0.00000001

其他应该都不是问题了,都是最基本的二分法 没一点扩展


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
double f(double v)
{
    return 8*v*v*v*v + 7*v*v*v+ 2*v*v + 3*v + 6;
}
double fabs(double v)
{
     return v>=0?v:-v;
}
int main()
{
     int n;
     cin>>n;
     while(n--)
     {
           double y;
              cin>>y;
            if(y<6||y>f(100))  printf("No solution!\n");
            else
           {
                    double left=0.0,right=100.0,mid=0.0;
                     while(fabs(right-left)>1e-8)
                      { 
                                  mid=(left+right)/2.0;
                                  if(f(mid)<y)  left=mid;
                                  else  right=mid;
                       }
                      printf("%.4lf\n",mid);
           } 
      }
  return 0;
}


目录
相关文章
codeforces 285C - Building Permutation
题目大意是有一个含n个数的数组,你可以通过+1或者-1的操作使得其中的数是1--n中的数,且没有重复的数。 既然是这样的题意,那么我就应该把原数组中的数尽量往他最接近1--n中的位置放,然后求差绝对值之和,但有多个数,怎么使他们和最小,这样就要对其进行排序了,直接按大小给它们安排好位置,然后计算。
34 0
|
6月前
|
Java
HDU-2199-Can you solve this equation
HDU-2199-Can you solve this equation
31 0
|
图形学
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
71 0
HDU-1097,A hard puzzle(快速幂)
HDU-1097,A hard puzzle(快速幂)
|
算法 Go
HDU-1548,A strange lift(Dijkstra)
HDU-1548,A strange lift(Dijkstra)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
125 0
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
109 0