Strange fuction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1612 Accepted Submission(s): 1206
F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)
Can you find the minimum value when x is between 0 and 100.
#include <cstdio>
#include <cmath>
double calc(double x,double yy)
{
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-yy*x;
}
int main()
{
int t;double y;
scanf("%d",&t);
while (t--)
{
scanf("%lf",&y);
double mid,mmid,le=0,ri=100.0;
while((ri-le)>1e-6)
{
mid=(ri+le)/2;
mmid=(mid+ri)/2;
if (calc(mid,y)<=calc(mmid,y))
ri=mmid;
else le=mid;
}
printf("%.4f\n",calc(mid,y));
}
return 0;
}