Strange fuction
2016-04-19 22:42
323 查看
[align=left]Problem Description[/align]
Now, here is a fuction:<br> F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)<br>Can you find the minimum value when x is between 0 and 100.
[align=left]Input[/align]
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)
[align=left]Output[/align]
Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
[align=left]Sample Input[/align]
2
100
200
[align=left]Sample Output[/align]
-74.4291
-178.8534
题意:求F(x)最小值
思路:一开始没有思路,然后参考了一下网上的思路,可以先求f',令f'=0,通过二分得出y与x的关系,有式子function(x0)= y,发现当x < x0,F(x)单调递减,当x > x0,F(x)单调递增,从而得到F(x)的最小值
代码:
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
const double eps = 1e-6;
double cal(double x){
return 42*pow(x,6.0)+48*pow(x,5.0)+21*pow(x,2.0)+10*x;
}
double get(double x,double y){
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-x*y;;
}
int main()
{
int T = 0;
double Y = 0.0;
double x = 0.0;
cin >> T;
while(T--){
cin >> Y;
double res = 0.0;
double low = 0.0;
double high = 100.0;
while(high - low > eps){
x = (high + low)/2;
res = cal(x);
if(res < Y){
low = x + 1e-8;
}
if(res > Y){
high = x - 1e-8;
}
}
double value = get(x,Y);
printf("%.4f\n",value);
}
return 0;
}
Now, here is a fuction:<br> F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)<br>Can you find the minimum value when x is between 0 and 100.
[align=left]Input[/align]
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)
[align=left]Output[/align]
Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
[align=left]Sample Input[/align]
2
100
200
[align=left]Sample Output[/align]
-74.4291
-178.8534
题意:求F(x)最小值
思路:一开始没有思路,然后参考了一下网上的思路,可以先求f',令f'=0,通过二分得出y与x的关系,有式子function(x0)= y,发现当x < x0,F(x)单调递减,当x > x0,F(x)单调递增,从而得到F(x)的最小值
代码:
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
const double eps = 1e-6;
double cal(double x){
return 42*pow(x,6.0)+48*pow(x,5.0)+21*pow(x,2.0)+10*x;
}
double get(double x,double y){
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-x*y;;
}
int main()
{
int T = 0;
double Y = 0.0;
double x = 0.0;
cin >> T;
while(T--){
cin >> Y;
double res = 0.0;
double low = 0.0;
double high = 100.0;
while(high - low > eps){
x = (high + low)/2;
res = cal(x);
if(res < Y){
low = x + 1e-8;
}
if(res > Y){
high = x - 1e-8;
}
}
double value = get(x,Y);
printf("%.4f\n",value);
}
return 0;
}
相关文章推荐
- MATLAB axis和axes的区别
- Install Git--MacOs X
- 【Android】图片切割
- lwip C/S模型调试 抓包看到常见的错误状态
- 从头认识多线程-1.16 对比不同的优先级
- <Puppet 集中配置管理系统RHEL6>
- ios 音视频处理优化总结
- Leetcode - Balanced Binary Tree
- poj3461 Oulipo(KMP)
- MJRefresh代码分析
- 视差贴图(Parallax Mapping)
- javascript代码规范 [转]
- ARM NEON 编程系列2 - 基本指令集
- 初步掌握MapReduce的架构及原理
- jsp界面的动态效果判断以及控件直接d动态关联,整数运算
- tsinsen A1036. 分解质因数
- ListView使用技巧
- 电子相册系统(二)业务层设计
- Android计算器界面 TableLayout
- 数据库-事务和锁