Strange fuction
2015-07-23 10:17
399 查看
C - Strange fuction
Time Limit:1000MS Memory Limit:32768KB 64bit
IO Format:%I64d & %I64u
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
Sample Output
这道题是求一个函数式的极值,可转化为求它导数等于0时的解,就变成了与前一道“Can
you solve this equation?”一样的模式。依然是二分法。
代码:
Time Limit:1000MS Memory Limit:32768KB 64bit
IO Format:%I64d & %I64u
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
这道题是求一个函数式的极值,可转化为求它导数等于0时的解,就变成了与前一道“Can
you solve this equation?”一样的模式。依然是二分法。
代码:
<span style="font-family:SimSun;font-size:14px;">#include<cstdio> #include<iostream> #include<cmath> using namespace std; int T; double l,r,mid,x,Y,t=1e-8; double v(double x){ return 42.0*pow(x,6) + 48.0*pow(x,5)+ 21.0*x*x + 10.0*x ; } double vs(double x,double Y){ return 6 *pow(x,7)+8*pow(x,6)+7*x*x*x+5*x*x-Y*x; } int main(){ cin>>T; while(T--){ cin>>Y; l=0; r=100; if((v(0)-Y>0)||(v(100.0)-Y<0)) { cout<<"No solution!"<<endl; break;} while(l<r){ mid=(l+r)/2; if(fabs(v(mid)-Y)<t) break; else if(v(mid)-Y<0) l=mid; else r=mid; } mid=(l+r)/2; printf("%.4lf\n",vs(mid,Y)); } return 0; } </span>
相关文章推荐
- __int64 与long long int
- java多线程基础学习2
- 08 vim编辑
- CentOS文件内容查阅命令(cat、tac、nl、more、less、head、tail、touch)
- STL set
- 种子填充找连通块 floodfill
- swift学习01-性能评测
- make 2>&1 | tee build.log 求解释
- java基础之 反射
- [leetcode] Longest Consecutive Sequence
- OI流水账(慎入)
- 使用Kotlin开发Android
- 安装多个jdk导致eclipse打不开问题解决
- codeforce(559B)
- (新)Android 汉子首字母排序
- Codeforces546C:Soldier and Cards
- jQuery选择器
- C++转让Lua
- 关于电信cdma基站nid,sid,bid的解释
- 创建数据上下文