hdu 2199 Can you solve this equation?

原创 2015年11月19日 08:51:51

Can you solve this equation?

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


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!
题型:二分查找
注意,,double型数据不能直接用等号,而应该作使差的绝对值小于一个足够小的数,,水题
#include<iostream> #include<cstdio> #include<cstring> #include<math.h> using namespace std; double y; double f(double x) {     return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6-y; } int main() {     int cas;     scanf("%d",&cas);     while(cas--)     {        scanf("%lf",&y);        if(f(0)>0||f(100)<0)        {           printf("No solution!\n");           continue;        }        double m,l=0,r=100;        while(r-l>=1e-8)        {             m=(l+r)/2.0;             if(f(m)<0)                l=m;             else                r=m;             if(fabs(f(m))<1e-8)                break;        }        printf("%.4lf\n",m);     }     return 0; }
 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/smilesundream/article/details/49922865

HDU:2199 Can you solve this equation?(二分)

Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...
  • zugofn
  • zugofn
  • 2016-07-27 00:21:07
  • 141

hdu 2199 Can you solve this equation?

Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...
  • zhenzheni
  • zhenzheni
  • 2015-08-11 23:06:02
  • 240

HDOJ 2199 Can you solve this equation?(二分查找)

Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...
  • zwj1452267376
  • zwj1452267376
  • 2015-07-30 11:33:02
  • 967

B - Can you solve this equation?

Description 现在,给出等式8* X^4+ 7* X^3+ 2* X^2+ 3 * X +6= Y,请找出他在0和100之间的解(包含0和100)。 现在,请你试试运气。。。。Input...
  • geekword
  • geekword
  • 2016-07-21 19:38:28
  • 528

杭电 HDU ACM 2199 Can you solve this equation?

Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...
  • lsgqjh
  • lsgqjh
  • 2015-05-01 10:01:50
  • 661

ACM-二分搜索之Can you solve this equation?——hdu2199

ACM 二分搜索 Can you solve this equation? hdu2199 精度判定
  • lx417147512
  • lx417147512
  • 2014-04-30 14:57:11
  • 1417

1001—Can you solve this equation?

1.题目序号:1001—Can you solve this equation? 2.题意:先输入n,再输入n个y,找出方程8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == y的...
  • houhouhhh
  • houhouhhh
  • 2016-04-17 23:27:09
  • 155

二分查找:hdu 2199 Can you solve this equation?

Can you solve this equation? Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x...
  • u012717411
  • u012717411
  • 2014-12-24 10:10:33
  • 1027

(hdu step 4.1.1)Can you solve this equation?(使用二分法来求解方程组的解)

题目:Can you solve this equation?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J...
  • caihongshijie6
  • caihongshijie6
  • 2015-02-16 13:11:54
  • 988

HDU--杭电--Can you solve this equation?--二分

Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...
  • hncu1206401liuhao
  • hncu1206401liuhao
  • 2013-11-25 21:51:03
  • 801
收藏助手
不良信息举报
您举报文章:hdu 2199 Can you solve this equation?
举报原因:
原因补充:

(最多只允许输入30个字)