hdu 2199 (二分)

链接: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 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!

------------------------------------------------------------------------------------------------------------、

 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         else
38             printf("%.4lf\n",left);
39     }
40
41 }

时间: 2024-08-26 10:38:15

hdu 2199 (二分)的相关文章

HDU 2199(二分求方程解)

关键是确定解的范围以及二分时的判断依据 这里解的范围已经确定,因为是递增函数,二分依据就是和Y的大小比较 #include"cstdio" #include"cstring" #include"algorithm" #include"cmath" #define MAXN 505 using namespace std; double cal(double x) { double temp=8.0*pow(x,4)+7.0*p

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 2255 二分图带权匹配 模板题

模板+注解在 http://blog.csdn.net/u011026968/article/details/38276945 hdu 2255 代码: //KM×î´ó×îСƥÅä #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; #define INF 0x0fffffff const int MAXN

Hdu 2389 二分匹配

题目链接 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)Total Submission(s): 2644    Accepted Submission(s): 823 Problem Description You’re giving a party in the garden of your villa by the sea. T

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

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 4737 二分或暴力

http://acm.hdu.edu.cn/showproblem.php?pid=4737 Problem Description There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . Where "|" is the bit-OR operation. (i <= j)

HDU 3656 二分+dlx判定

Fire station Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1308    Accepted Submission(s): 434 Problem Description A city's map can be seen as a two dimensional plane. There are N houses in

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

(二分)Can you solve this equation? -- hdu -- 2199

链接: http://acm.hdu.edu.cn/showproblem.php?pid=2199 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13475    Accepted Submission(s): 6010 Problem Description Now,given the equation 8*x^4 + 7*x^3