码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-02-28 18:36:30      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #define sc(x) scanf("%d",&(x))
 5 #define pf(x) printf("%.4lf\n", x)
 6 using namespace std;
 7 int T;
 8 double Y;
 9 double r(double x)
10 {
11     return (8*pow(x, 4) + 7*pow(x, 3) + 2*pow(x, 2) + 3*x + 6);
12 }
13 double Find()
14 {
15     double front = 0, rear = 100, mid;
16     while((rear - front) > 1e-6)
17     {
18         mid = (front + rear) / 2;
19         if(r(mid) < Y)
20             front = mid + 1e-7;
21         else
22             rear = mid - 1e-7;
23     }
24     return (front + rear) / 2;
25 }
26 int main()
27 {
28     sc(T);
29     while(T--)
30     {
31         cin >> Y;
32         if(r(0) <= Y && Y <= r(100))
33             pf(Find());
34         else
35             cout << "No solution!" << endl;
36     }
37     return 0;
38 }
View Code

 

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

标签:

原文地址:http://www.cnblogs.com/tyx0604/p/4305950.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!