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;
}


目录
相关文章
|
7月前
|
Java
HDU-2199-Can you solve this equation
HDU-2199-Can you solve this equation
34 0
|
图形学
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
75 0
LeetCode 221. Maximal Square
在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积。
65 0
LeetCode 221. Maximal Square
|
算法 Go
HDU-1548,A strange lift(Dijkstra)
HDU-1548,A strange lift(Dijkstra)
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
111 0
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
128 0
|
机器学习/深度学习