您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: