从零开始刷HDOJ(3)【HDOJ2899
来源:互联网 发布:最短路径的floyd算法 编辑:程序博客网 时间:2024/06/05 20:40
从零开始刷HDOJ(3)【HDOJ2899 - Strange function 】
题面
Strange fuction
Time limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7321 Accepted Submission(s): 5057
Problem Description
Now, here is a function:
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
提交传送门:Submit
翻译
就是把求一下当
思路
其实这个函数在[0, 100]上是单峰的。
Proof:
既然我们可以证明
代码
#include <cmath>#include <iostream>// F(x) = 6x7 + 8x6 + 7x3 + 5x2 – xy double y;inline double f(const double x){ return 6 * std::pow(x, 7) + 8 * std::pow(x, 6) + 7 * std::pow(x, 3) + 5 * std::pow(x, 2) - y * x;}inline double F(const double x){ return 42 * std::pow(x, 6) + 48 * std::pow(x, 5) + 21 * std::pow(x, 2) + 10 * x;}int main(int argc, char ** argv){ std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed); std::cout.precision(4); double ans; double l = 0.0, r = 100.0; int times = 1000; int T; std::cin >> T; while (T--) { std::cin >> y; l = 0.0; r = 100.0; times = 10000; double eps = 1e-10; while (times--) { double mid = (l + r) / 2.0; if (F(mid)>y) r = mid; else l = mid; } std::cout << f(l) << std::endl; } std::cin.get(); std::cin.get(); return 0;}
- 从零开始刷HDOJ(3)【HDOJ2899
- 从零开始刷HDOJ(1)【HDOJ1000
- 从零开始刷HDOJ(2)【HDOJ1001
- [二分]HDOJ2899 Strange fuction
- HDOJ2899(二分,三分两种方法)
- arm从零开始3
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 从零开始
- 牧师与魔鬼(动作分离版)
- JQuery表单验证之密码确认
- 进程通信之共享内存
- Linux脚本攻略学习笔记11
- TextRank算法为文本生成关键字和摘要
- 从零开始刷HDOJ(3)【HDOJ2899
- centos yum 安装 jdk
- css3中单位px,em,rem,vh,vw,vmin,vmax的区别及浏览器支持情况
- (52)组件之摄像机组件
- 配置电子邮件传输
- IDEA中maven项目导入依赖包太慢,因为你的中央仓库配置的国外....
- HDU 1170 Balloon Comes!
- @RequestMapping @Responsebody与@RequestBody @PathVariable
- 人民币,大写中文与数字之间转换