您的位置:首页 > 其它

HDU 2899 Strange fuction(二分,三分)

2017-07-30 12:57 393 查看


Strange fuction

Time Limit: 2000/1000 MS (Java/Others)    Memory
Limit: 32768/32768 K (Java/Others)

Total Submission(s): 80    Accepted Submission(s): 62

Problem Description

Now, here is a fuction:

  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.

 

 

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 only one real numbers Y.(0 < Y <1e10)

 

 

Output

Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.

 

 

Sample Input

2
100
200

 

 

Sample Output

-74.4291
-178.8534

之前用二分做过了一次,这次用三分做一次,可以说是三分的入门题吧

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;

int y;
double f(double x){
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
}

int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&y);
double l=0,r=100;
double mid,mmid;
while(r-l>eps){
mid=(r+l)/2.0;
mmid=(mid+r)/2.0;
double tmp1=f(mid);
double tmp2=f(mmid);
if(tmp1<tmp2)
r=mmid;
else
l=mid;
}
// double ans=6*pow(l,7)+8*pow(l,6)+7*pow(l,3)+5*pow(l,2)-y*l;
printf("%.4f\n",f(l));

}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM OJ hdu