HDU 2899 Strange fuction(二分,三分)
2017-07-30 12:57
393 查看
Strange fuction
Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 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;
}
相关文章推荐
- hdu 2899 Strange fuction 【二分,三分】
- Hdu 2899 Strange fuction(二分三分可做,模拟退火解法)
- HDU 2899 Strange fuction(二分或三分)
- HDU 2899 Strange fuction(二分||三分)
- HDU - 2899 Strange fuction 二分/三分
- Hdu 2899 - Strange fuction 二分/三分求函数极值点
- HDU 2899 Strange fuction(三分)
- HDU 2899 Strange Fuction(二分查找)
- hdu 2899 Strange fuction (求导 + 二分)
- hdu 2199 2899 (二分,三分)
- hdu_2899_Strange fuction(三分查找)
- HDU 2899 Strange fuction(三分)
- hdu 2899 Strange fuction(用三分即可 不用求导)
- hdu 2899 Strange fuction (二分)
- hdu_2899_Strange fuction(三分查找)
- HDU 2899 Strange fuction(二分)
- hdu2899 简单数学+二分+三分
- hdu2899 Strange fuction 三分搜索
- HDU—2899—strange fuction—【二分】【精度控制】
- HDU--杭电--2899--Strange fuction--二分