hdu 2899 Strange fuction 三分
2015-09-01 16:44
429 查看
Strange fuction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4854 Accepted Submission(s): 3459
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
Author
Redow
Recommend
lcy | We have carefully selected several similar problems for you: 2199 2289 2298 2141 3400
求导可知,随参数y值的变化,该函数在定义域内,要么单调递减,要么先递减后递增,故可用三分法求最小值。
double y; double f(double x) { return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x; } double solve(double le,double ri) { double mid, midmid; while(ri-le>0.0000001) { mid=(le+ri)/2; midmid=(mid+ri)/2; if(f(mid)<f(midmid) ) ri=midmid; else le=mid; } return f(mid); } int main() { int T;scanf("%d",&T); while(T--) { scanf("%lf",&y); printf("%.4lf\n",solve(0.0,100.0) ); } return 0; }
头文件:
#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<climits> #include<queue> #include<vector> #include<map> #include<sstream> #include<set> #include<stack> #include<utility> #pragma comment(linker, "/STACK:102400000,102400000") #define PI 3.1415926535897932384626 #define eps 1e-10 #define sqr(x) ((x)*(x)) #define FOR0(i,n) for(int i=0 ;i<(n) ;i++) #define FOR1(i,n) for(int i=1 ;i<=(n) ;i++) #define FORD(i,n) for(int i=(n) ;i>=0 ;i--) #define lson num<<1,le,mid #define rson num<<1|1,mid+1,ri #define MID int mid=(le+ri)>>1 #define zero(x)((x>0? x:-x)<1e-15) #define mk make_pair #define _f first #define _s second using namespace std; const int INF =0x3f3f3f3f; //const int maxn= ; //const int maxm= ; //const int INF= ; typedef long long ll; const ll inf =1000000000000000;//1e15; //ifstream fin("input.txt"); //ofstream fout("output.txt"); //fin.close(); //fout.close(); //freopen("a.in","r",stdin); //freopen("a.out","w",stdout); //by yskysker123
相关文章推荐
- Ext错误"Uncaught SyntaxError: Unexpected token <"
- 提高mysql的写入效率
- 大话设计模式笔记 策略模式
- 问题:oracle CLOB类型;结果:oracle中Blob和Clob类型的区别
- iscsi 华为存储配置 上课内容
- 你在过度测试你的软件吗?
- Nouveau源码分析(零)
- JSP - Directives
- POJ1840——哈希——Eqs
- 高阶函数之函数柯里化function currying
- Talend 显示隐藏控件-thashmap
- Jquery
- Docker中的Volume
- 密码破解之Esxi重置root密码
- POJ 3268 Silver Cow Party
- TCP FIN_WAIT_2状态问题分析
- Android问题集(一)——从fragment跳转到另一个Activity
- 09.01,学习习题
- 历史不会偏袒任何一个缺乏正义、良知的人。
- 9.在项目中利用block替换代理方法,实现通知