Strange fuction
来源:互联网 发布:云计算 安全问题 编辑:程序博客网 时间:2024/05/21 19:45
Strange fuction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6879 Accepted Submission(s): 4812
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.
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
2100200
Sample Output
-74.4291-178.8534
Author
Redow
思路 : 这个是求一个方程组值,所以可以用二分 , 要用 二分 :条件 单调性要确定 。。所以要求导来判断。
又因为一介导 的x有区间且有个未知数y 。分类讨论;1 可能整体上都是单增,极小值就是 x==0时候取2 可能整体上都是单减 ,此时极小值就是x==100 时候取3 也可能为有增有减 ,此时候极小值就是在 极小值点取得 (即一介导为零的地方)。。对于这种分类讨论 画图看会更明白;
代码
#include<stdio.h>
#include<math.h>
double y;
double f(double x) //原函数
{
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x;
}
double f1(double x) // 一介导函数
{
return 42*pow(x,6)+48*pow(x,5)+21*x*x+10*x-y;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&y); // 整体上单增的时候,y<0 但是题目上y>0 所以这种情况不用讨论
if(f1(100.0)<0) // 这个条件是 整体上单减,一介导恒小于0;
{
printf("%.4lf",f(100.0));
continue ;
}
double left,right,mid;
left=0.0;right=100.0; // 接下来就是求 有增有减的情况
while(right-left>1e-10)
{
mid=(right+left)/2;
if(f1(mid)>0) right=mid;
if(f1(mid)<0) left=mid;
}
printf("%.4lf\n",f(right)); // 因为精度足够高,远远高于题目要求,所以输出right,left,mid 都是没有问题的
}
}
#include<math.h>
double y;
double f(double x) //原函数
{
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x;
}
double f1(double x) // 一介导函数
{
return 42*pow(x,6)+48*pow(x,5)+21*x*x+10*x-y;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&y); // 整体上单增的时候,y<0 但是题目上y>0 所以这种情况不用讨论
if(f1(100.0)<0) // 这个条件是 整体上单减,一介导恒小于0;
{
printf("%.4lf",f(100.0));
continue ;
}
double left,right,mid;
left=0.0;right=100.0; // 接下来就是求 有增有减的情况
while(right-left>1e-10)
{
mid=(right+left)/2;
if(f1(mid)>0) right=mid;
if(f1(mid)<0) left=mid;
}
printf("%.4lf\n",f(right)); // 因为精度足够高,远远高于题目要求,所以输出right,left,mid 都是没有问题的
}
}
0 0
- Strange fuction
- Strange fuction
- Strange fuction
- Strange fuction
- Strange Fuction
- Strange fuction
- Strange fuction
- 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
- [二分]HDOJ2899 Strange fuction
- HDU2899 Strange fuction 【二分】
- hdu 2899 Strange fuction
- hdu--2899--Strange fuction
- 修改centos7防火墙设置
- JSP中WEB项目常用开头
- PreAngel投资过的公司列表
- 机器学习之协同过滤
- 智能硬件无线通信协议的那些事儿(一)
- Strange fuction
- [Kafka]
- 选择法排序升级版
- (2017.2.25)新い ストーリー
- SAPUI5 (22)
- Struts2文件上传参数
- android利用HttpURLConnection+XmlPullParser解析Xml文件
- 安装Kail linux双系统 出现错误your installation CD-ROM couldn't be mounted
- Excel.Application使用手册