三分 - HNU 13409 Flowers

Flowers

Problem‘s Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13409&courseid=0



Mean:

有N颗种子,每颗种子初始时营养值为0。当一颗种子营养值达到th后就会开花。

有两种操作:

1.给所有的种子浇w升水;

2.给某个种子施f升肥;

对于第i颗种子,每浇1升水会增加vw点营养值,每施1升肥可以增加vf点营养值,该种种子的肥料单价为pf,当营养值达到th后开花。

浇水必须一起浇,而且水的单价是一样的,都是pw。花的th可能为负,而且有的花浇水营养值会减少。

analyse:

很明显的凸函数。

由于浇水的量所有种子都相同,所以三分水量即可。

Time complexity: O(N)

Source code: 

/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-08-16-19.52
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define eps 1e-14
#define  LL __int64
#define  ULL unsigned __int64
using namespace std;
const int MAXN=10+(int)1e5;
LL n,pw,vw[MAXN],pf[MAXN],vf[MAXN],th[MAXN];
double tmp,t;
double cal(double& w)
{
     tmp=w*pw;
     for(int i=0;i<n;++i)
     {
           t=th[i]-w*vw[i];
           if(t<=0) continue;
           tmp+=(t)*pf[i]*1./vf[i];
     }
     return tmp;
}

double work(double l,double r)
{
     double mid,mmid;
     int st=100;
     while(st--)
     {
           mid=(l+r)/2;
           mmid=(mid+r)/2;
           if(cal(mid)-cal(mmid)>eps)
                 l=mid;
           else r=mmid;
     }
     return l;
}
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     while(scanf("%I64d",&n),n)
     {
           scanf("%I64d",&pw);
           for(int i=0;i<n;++i)
           {
                 scanf("%I64d %I64d %I64d %I64d",&vw[i],&pf[i],&vf[i],&th[i]);
           }
           double val=work(0,200);
           printf("%.6lf\n",cal(val));
     }
     return 0;
}
/*

*/

时间: 2024-08-07 21:20:23

三分 - HNU 13409 Flowers的相关文章

Flowers 三分

Flowers 题目抽象:给你一些数据,给你公式(不是简单公式),求最小值. 分析:公式都给出了,又是求最值,很自然的想法是二分,或者三分.这题显然不是二分.那么就是三分了.已水量为变量,那么化肥的量的最小值就可以求出.比赛的时候虽然不能证明该函数为吐函数,但是很容易猜想到是三分. 1 /******************************** 2 please don't hack me!! /(ToT)/~~ 3 __------__ 4 /~ ~ 5 | //^\\//^\| 6

HNU 13375 Flowery Trails (最短路)

Flowery Trails Time Limit: 50000ms, Special Time Limit:125000ms, Memory Limit:65536KB Total submit users: 23, Accepted users: 21 Problem 13375 : No special judgement Problem description Input The first line of the input has two integers: P and T. P i

贪心 --- HNU 13320 Please, go first

Please, go first Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13320 Mean: n个人一起去滑雪,要坐电梯到山顶,电梯每5分钟可以送一个人上去.这n个人中有的是组好团一起滑雪的,所以要等到齐了才能开始滑. 但是他们到达电梯下的时间都不是统一的,对于单独一个人来说,他在山下等和在山上等的时间都是一样的. 但是对于n个人的集体来说,如果让他后面的人先上去,这样可能会更节省时间.

HNU 12885 Bad Signal(模拟)

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12885&courseid=274 解题报告:一共有n个发射装置,有一个接收装置,接收装置能够正确接收并把接收到的信号准确的译码出来的条件是: Ti > 6 * (B +(T1 + T2 + .... Ti-1 + Ti+1.....Tn)) 然后Ti = si / (Pi - p) si是信号强度 pi - p的意思是发射器跟接收器之间的直线距离的平方 暴

hdu 4717 The Moving Points(三分)

题目链接:hdu 4717 The Moving Points 题意: 在二维平面上有n个点,每个点给出移动的方向和速度. 问在某个时刻,这些点中最大距离最小是多少,输出时刻和距离. 题解: 我们可以知道,每个点对的距离要么是单调递增,要么是有一个峰的函数. 举例画一下可知道合成的这个函数最多只有一个峰,所以可以用三分求解. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespa

三分算法

三分算法 二分算法解决的是具有单调性的问题. 三分算法解决的是抛物线的类型,上凸,下凹. mid=(Left+Right)/2; midmid=(Right+mid)/2; 题目类型有: HDU :3400  2298  4454  2438  3756 POJ:  3301   3737 ZOJ: 3203

Flowers(二分水过。。。)

Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2579    Accepted Submission(s): 1265 Problem Description As is known to all, the blooming time and duration varies between different kinds

uvalive 4986(三分查找)

题意:空间内有n个点,求一个最小体积的圆锥把所有点包进去.输出圆锥的高和底面半径.圆锥的底面圆心在(0,0),所有点的z坐标都大于等于0. 题解:因为圆锥体积是 V = 1/3 * π * r^2 * h ,这是一个二次函数,也就是个凸性函数,可以用三分查找的方式枚举两个高,然后找到对应的最小的r,比对两个高得到的体积继续三分查找. #include <cstdio> #include <cstring> #include <algorithm> #include &l

Toxophily-数论以及二分三分

G - Toxophily Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2298 Description The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballroom