hdu 2199 Can you solve this equation?

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199

题目大意:找到满足8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y的x值,注意精确度问题。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4
 5 using namespace std;
 6
 7
 8 double fun(double s)
 9 {
10     return 8*pow(s, 4.0) + 7*pow(s, 3.0) + 2*pow(s, 2.0) + 3*s + 6;
11 }
12 int main ()
13 {
14     int t,flag;
15     cin>>t;
16     while (t--)
17     {
18         flag=0;
19         double x,y,yy,r,l;
20         cin>>y;
21         if (fun(0)<=y&&fun(100)>=y)
22         {
23             r=0,l=100;
24             while (l-r>1e-6)
25             {
26                 //cout<<r<<endl;
27                 x=(r+l)/2;
28                 double yy=fun(x);
29                 //yy=8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
30                 //yy=8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
31                 if (yy>y)
32                     l=x+1e-7;
33                 else
34                     r=x+1e-7;
35
36             }
37             printf ("%.4lf\n",(r+l)/2);
38             //break;
39             flag=1;
40         }
41         else
42             {printf ("No solution!\n");flag=1;}
43         if (yy==r&&flag==0)
44             printf ("%.4lf\n",y);
45         else if (flag==0)
46             printf ("No solution!\n");
47
48     }
49     return 0;
50 }

hdu 2199 Can you solve this equation?,布布扣,bubuko.com

时间: 2024-12-20 16:41:44

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): 7493    Accepted Submission(s): 3484 Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,

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

HDU 2199 Can you solve this equation? 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. InputThe first line of the input contains an integer T(1<=T<=100) which means t

hdu 2199 Can you solve this equation?(高精度二分)

http://acm.hdu.edu.cn/howproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13468    Accepted Submission(s): 6006 Problem Description Now,given the

HDU 2199 Can you solve this equation?【二分查找】

解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)<=y<=f(100),就一定能找到该方程的解,否则就无解. 然后是求解过程, 假设一个区间[a,b],mid=(a+b)/2,如果f(a)*f(b)<0,那么函数f(x)在区间[a,b]至少存在一个零点,如果f(a)<0,说明0点在其右侧,那么将a的值更新为当前mid的值,如果f(a)&g

ACM: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): 16281 Accepted Submission(s): 7206 Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can

hdu 2199~Can you solve the equation?~二分法求解

Can you solve this equation? Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 28   Accepted Submission(s) : 17 Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can y

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

题目链接 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

HDU 2199 Can you solve this equation?(水题吗?!)

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 tes

hdu 2199 Can you solve this equation?(二分法求多项式解)

题意 给Y值,找到多项式 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y 在0到100之间的解. 思路 从0到100,多项式是单调的,故用二分法求解. 代码 double calc(double x){ return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6; } int main(){ int T; cin>>T; while(T--){ double Y; cin>>Y; double L,R; L = 0.0, R= 100.0;