HDU 2899 Strange fuction
2016-07-21 14:46
260 查看
题目:
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
这个题目和DU 2199 Can you solve this equation?差不多,不过没有了昨天那个EPS的精度的问题。
很容易看出来,F(x)在区间(0,100)就是先递减后递增,利用这个作为二分查找时选择左右的依据即可。
代码:
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
这个题目和DU 2199 Can you solve this equation?差不多,不过没有了昨天那个EPS的精度的问题。
很容易看出来,F(x)在区间(0,100)就是先递减后递增,利用这个作为二分查找时选择左右的依据即可。
代码:
#include<stdio.h> int main() { int t; scanf("%d", &t); double y; while (t--) { scanf("%lf", &y); double low = 0, high = 100; double m; double mmm; while (low + 0.0000001 < high) { m = (low + high) / 2; mmm = m*m*m; if (((42 * mmm + 48 * m*m)*mmm + 21 * m*m + 10 * m)>y)high = m; else low = m; } printf("%.4lf\n", (6*m+8)*mmm*mmm+7*mmm+5*m*m-y*m); } return 0; }
相关文章推荐
- HTTP协议特点
- java.lang.ArrayIndexOutOfBoundsException: 160
- Android调用相机之后在相册中找不到这个照片的解决办法
- 前端开发入门-Hbuilder编辑器使用方法
- mysql开启root用户可远程登录方法
- C语言之移位操作
- 二维数组和二级指针(转)
- java.lang.ArrayIndexOutOfBoundsException: 160
- 扬尘监测原理
- rapidxml 解析数组字段
- 初学 JAVA ,编程实例【人会说话,中国人说中国话,美国人说英语】
- 操作redis,把redis做成一个服务(PATH操作)
- cocos2dx-3.11 使用创建Lua项目以及运行自定义场景
- 最简单的SD卡文件遍历Android程序
- ZS4T简介
- 数据挖掘——变量选择
- 移动App架构设计
- Apache Shiro学习笔记(二)身份验证源码分析
- Java的线程同步 & 并发操作
- 一元购计算幸运号码