Problem Description
Problem Analysis
Binary search the answer
Comparing with Y tells us the relationship between mid and res
Note that x ranges over 0~100
Because the function f(m)=8m4+7m3+2*m2+3*m+6
is monotonically increasing on 0~100
So if Y<f(0)||Y>f(100) there is no solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| #include<stdio.h>
double n;
double f(double m) {
return 8*m*m*m*m+7*m*m*m+2*m*m+3*m+6;
}
bool judge(double m) {
if(f(m)>n)
return true;
else
return false;
}
int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%lf",&n);
if(n<f(0.0)||n>f(100.0)) {
printf("No solution!\n");
continue;
}
double r=10000000000,l=0,res;
while(r-l>1e-6) {
double mid=(r+l)/2;
if(judge(mid)) {
res=mid;
r=mid;
} else
l=mid;
}
printf("%.4lf\n",res);
}
return 0;
}
|