zoukankan      html  css  js  c++  java
  • 三分

    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 ",cal(val));
         }
         return 0;
    }
    /*

    */
  • 相关阅读:
    IO 单个文件的多线程拷贝
    day30 进程 同步 异步 阻塞 非阻塞 并发 并行 创建进程 守护进程 僵尸进程与孤儿进程 互斥锁
    day31 进程间通讯,线程
    d29天 上传电影练习 UDP使用 ScketServer模块
    d28 scoket套接字 struct模块
    d27网络编程
    d24 反射,元类
    d23 多态,oop中常用的内置函数 类中常用内置函数
    d22 封装 property装饰器 接口 抽象类 鸭子类型
    d21天 继承
  • 原文地址:https://www.cnblogs.com/crazyacking/p/4735188.html
Copyright © 2011-2022 走看看