hdu 2199 (二分)

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   java   os   io   strong   

連結:http://acm.hdu.edu.cn/showproblem.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): 8595    Accepted Submission(s): 3957


Problem DescriptionNow,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 the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y) <= 1e10); 

 

OutputFor 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 Input2100-4 

 

Sample Output1.6152No solution! ------------------------------------------------------------------------------------------------------------、
 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <iostream> 5 #include <algorithm> 6 #include <math.h> 7 #define eps 1e-8 8 using namespace std; 9 10 double fx(double x)11 {12     return 8*pow(x,4)+7*pow(x,3)+2*x*x+3*x+6;13 }14 15 int main()16 {17     int n,m,i,j;18     double y;19     double left=0,right=100,ans;20     scanf("%d",&n);21     while(n--)22     {23         scanf("%lf",&y);24         left=0.0,right=100.0;25         //ans=-100000;26         bool flag=true;27         while(right-left>eps)28         {29             double mid=(left+right)/2.0;30             if(fx(mid)-y< 0)31                  left=mid+eps;32             else right=mid-eps;33             //if()flag=false;34         }35         if(y>fx(100) || y<fx(0))36             printf("No solution!\n");37         else38             printf("%.4lf\n",left);39     }40 41 }
View Code

 

hdu 2199 (二分)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.