Flowers 三分
2015-08-17 10:13
218 查看
Flowers
题目抽象:给你一些数据,给你公式(不是简单公式),求最小值。
分析:公式都给出了,又是求最值,很自然的想法是二分,或者三分。这题显然不是二分。那么就是三分了。已水量为变量,那么化肥的量的最小值就可以求出。比赛的时候虽然不能证明该函数为吐函数,但是很容易猜想到是三分。
题目抽象:给你一些数据,给你公式(不是简单公式),求最小值。
分析:公式都给出了,又是求最值,很自然的想法是二分,或者三分。这题显然不是二分。那么就是三分了。已水量为变量,那么化肥的量的最小值就可以求出。比赛的时候虽然不能证明该函数为吐函数,但是很容易猜想到是三分。
/******************************** please don't hack me!! /(ToT)/~~ __------__ /~ ~\ | //^\\//^\| /~~\ || T| |T|:~\ | |6 ||___|_|_||:| \__. / o \/' | ( O ) /~~~~\ `\ \ / | |~~\ | ) ~------~`\ /' | | | / ____ /~~~)\ (_/' | | | /' | ( | | | | \ / __)/ \ \ \ \ \/ /' \ `\ \ \|\ / | |\___| \ | \____/ | | /^~> \ _/ < | | \ \ | | \ \ \ -^-\ \ | ) `\_______/^\______/ ************************************/ #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cstdlib> #include <sstream> using namespace std; typedef long long LL; const LL INF = 0x5fffffff; const double EXP = 1E-8; const LL MOD = (LL)1E9+7; const int MS = 100005; struct node { double vw,pf,vf,th; }nodes[MS]; int main() { int T, N; double pw; while (scanf("%d",&N) == 1) { if (N == 0) break; scanf("%lf",&pw); for (int i = 0; i < N; i++) { scanf("%lf%lf%lf%lf",&nodes[i].vw,&nodes[i].pf,&nodes[i].vf,&nodes[i].th); } double l = 0; //枚举水量 double r = 101; double sum1, sum2; // 用三分的次数代替浮点数的比较。 for (int time = 1; time < 200; time++) { double mid = l + (r - l) / 3; double mmid = r - (r - l) / 3; sum1 = mid * pw; sum2 = mmid * pw; for (int i = 0; i< N;i++) { double t = nodes[i].th - mid * nodes[i].vw; if(t <= 0) continue; sum1 += t / nodes[i].vf * nodes[i].pf; } for (int i = 0; i< N;i++) { double t = nodes[i].th - mmid * nodes[i].vw; if(t <= 0) continue; sum2 += t / nodes[i].vf * nodes[i].pf; } if (sum1 > sum2) l = mid; else r = mmid; } printf("%.5lf\n",sum1); } return 0; }
相关文章推荐
- Android开发常见问题
- Linux 常用命令详解
- oneproxy中间件架构及注意事项
- oneproxy中间件架构及注意事项
- 程序员必备技能
- Python+client_connection.sendall(http_resp)+TypeError: 'str' does not support the buffer interface
- SCI写作总结
- [.Net码农]asp.net下载文件几种方式
- mac环境python Flask 环境搭建
- C#读取Excel 几种方法的体会
- Hits算法
- wamp新建虚拟目录无法运行的解决方法
- centos6.5 下 Oracle 11g的删除
- iOS 面试常见问题总结
- jQuery--包裹节点
- QVariant类
- Unity5的AssetBundle的一点使用心得
- C语言——数组知识大汇总
- 创建 event_base
- Flume搭建