2002
2016-04-05 08:30
120 查看
题目编号:2002
简单题意:
Problem Description
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.
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<br>100<br>200
Sample Output
-74.4291<br>-178.8534
Author
Redow
给定一个函数方程,求给定范围内函数的最值。
解题思路:求最值,首先想到求导。二次求导发现原函数单调递减。当一阶导数为0时,函数可以得到最小值。所以,使用二分法+求导解方程可以得到结果;
AC代码:#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double f(double x,long long y)
{
return (42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y);
}
int main()
{
int t;
cin>>t;
while(t--)
{
double mid=50.0,m=0.0,n=100.0,x,s;
long long y;
cin>>y;
while(fabs(f(mid,y))>1e-5)
{
if((f(mid,y)>0))
{
n=mid;
mid=(m+n)/2;
}
else if(f(mid,y)<0)
{
m=mid;
mid=(m+n)/2;
}
}
x=mid;
s=6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x;
printf("%.4lf\n",s);
}
return 0;
}
简单题意:
Problem Description
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.
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<br>100<br>200
Sample Output
-74.4291<br>-178.8534
Author
Redow
给定一个函数方程,求给定范围内函数的最值。
解题思路:求最值,首先想到求导。二次求导发现原函数单调递减。当一阶导数为0时,函数可以得到最小值。所以,使用二分法+求导解方程可以得到结果;
AC代码:#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double f(double x,long long y)
{
return (42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y);
}
int main()
{
int t;
cin>>t;
while(t--)
{
double mid=50.0,m=0.0,n=100.0,x,s;
long long y;
cin>>y;
while(fabs(f(mid,y))>1e-5)
{
if((f(mid,y)>0))
{
n=mid;
mid=(m+n)/2;
}
else if(f(mid,y)<0)
{
m=mid;
mid=(m+n)/2;
}
}
x=mid;
s=6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x;
printf("%.4lf\n",s);
}
return 0;
}
相关文章推荐
- 适配器模式
- C#多线程网页采集器(Spider)
- 宏碁台式机,如何设置u盘启动
- gc函数
- jQuery动画
- tcp三次握手四次挥手详解
- 【BZOJ1101】[POI2007]Zap【Mobius函数】
- 现代软件工程第五周作业
- 【BZOJ3172】单词,AC自动机练习
- Django 1.6 CBVs
- 吃饭时间加强家庭关系
- bash 数组
- 一个App完成入门篇(五)- 完成新闻页面
- 类型转换
- cocos2dx 运动+旋转动画 CCSequence CCAnimation CCAnimate CCMoveTo CCCallFuncN
- Android 中进程、线程的概念
- bzoj 1452: [JSOI2009]Count
- 学习笔记4/5(相对布局 布局文件顺序问题
- git clone branch 远程分支
- [小技巧] FTP Server 设定禁止的文件名/目录名