题目:

The cascade of water slides has been installed in the park recently and it has to be tested. The cascade consists of some number of reservoirs, or “ponds” for short, which are linked into a single sequence connected by water slides. Visitors are expected to start the journey in the topmost pond, then to be washed into subsequent lower ponds, and finally end the journey in the last pond of the cascade, which is also the lowest pond of the cascade. The journey spans all ponds in the cascade.

To test the cascade, each pond has to be completely filled with water. Each pond is attached to a pipe with a valve which, when opened, pours water into the pond. The sizes and capacities of different ponds are different. Fortunately, at least the pipes and the valves are standardized. Therefore, the rate at which water is poured through the valve into a pond is the same for all ponds.

When a pond is filled, water overflows and continues to flow into the next pond. If that pond is also filled, water continues to the next subsequent pond, and so on, until it either reaches some pond which has not been completely filled yet, or it overflows the lowest pond and sinks in the drain at the bottom of the cascade. The time in which the overflowing water reaches the next pond is considered to be negligible. The test starts at time 0 with all ponds being empty. Then, all valves are opened simultaneously. The test stops and the valves are closed when all ponds are filled by water.

The pond capacities and valves flow rate are known, you have to determine the moment when the lowest pond starts to overflow and the first moment when all ponds are filled.

Input Specification:

There are more test cases. Each test case consists of two lines. The first line contains two integers N (1 ≤ N ≤ 105 , 1 ≤ F ≤ 109 ) separated by space. N is the number of ponds, F is the rate of water flow through each valve. We consider the flow to be expressed in litres per second. The second line contains a sequence of N integers Ci (1 ≤ Ci ≤ 109 ) separated by spaces and representing the pond capacities expressed in litres. The sequence reflects the order of ponds from the topmost one to the lowest one.

Output Specification:

For each test case, print a single line with two numbers separated by space. The first number represents the time in which the lowest pond in the cascade starts to overflow. The second number represents the duration of the test. Both times should be printed in seconds and should be accurate within an absolute or relative error of 10-6.

题目大意:

从上到下给出N个池塘,每个池塘都有水管与它相连,每个水管的流量都是flow,当上一层的池塘的水满了之后,该池塘剩余流入的水就会依次流入下边的池塘中,问最后一个池塘灌满的时间和全部池塘被灌满的时间。

思路:

这道题一开始拿过来首先想到的是贪心,但是错了,赛后看了看问题才知道,在统计所有池塘都被水填满的时候,是直接把所有池塘的容量加起来然后除以流速乘以N,想了想当时可能是傻了,因为下面的水塘先满对上面没有被填满的水塘是没有影响的,可能我就是个弟弟,至于最后的那个鱼塘只需要逆序一遍即可。之后看了看别人的代码,有很多人使用了二分枚举,个人对这一部分一直比较生疏,所以在这里也对二分求解进行了整理,大体的步骤是枚举很可能完成的时间段,然后进行多次二分,注意这里要进行次数的规范否则会出现死循环,以二分的搜索效率100-50次足以对很大的数据进行很多次的搜索了。

下面给出两种思想的AC代码:

贪心:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=1e6+100;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
ll n,flow,c[maxn];double judgegre_all()
{double time=-1e9;ll sum=0;for(int i=1;i<=n;i++){sum+=c[i];time=max(time,sum*1.0/(flow*i));}return time;
}double judgegre_final()
{double time=1e9;ll sum=0;for(int i=n;i>=1;i--){sum+=c[i];time=min(time,sum*1.0/(flow*(n-i+1)));}return time;
}int main()
{//ios::sync_with_stdio(false);while(scanf("%lld %lld",&n,&flow)!=EOF){for(int i=1;i<=n;i++) scanf("%lld",&c[i]);double time_all=judgegre_all();double time_final=judgegre_final();printf("%.6f %.6f\n",time_final,time_all);}return 0;}

二分枚举:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=1e6+100;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
ll n,flow,c[maxn];bool judgegre_all(double t)
{ll sum=0;for(int i=1;i<=n;i++){sum+=c[i];if(sum>flow*t*i) return false;}return true;
}double judgegre_final(double t)
{if(judgegre_all(t)) return true;ll sum=0;for(int i=n;i>=1;i--){sum+=c[i];if(t*flow*(n-i+1)>sum) return true;//注意这里的判断条件只要有一次满足就符合}return false;
}int main()
{//ios::sync_with_stdio(false);while(scanf("%lld %lld",&n,&flow)!=EOF){for(int i=1;i<=n;i++) scanf("%lld",&c[i]);double l=0,r=INF,mid,time_all,time_final;for(int i=1;i<=100;i++){mid=(l+r)/2;if(judgegre_all(mid)) r=mid;else l=mid;}time_all=mid;l=0,r=INF;for(int i=1;i<=100;i++){mid=(l+r)/2;if(judgegre_final(mid)) r=mid;else l=mid;}time_final=mid;printf("%.6f %.6f\n",time_final,time_all);}return 0;}

Pond Cascade Gym - 101670B 解题报告相关推荐

  1. B - Pond Cascade Gym - 101670B

    本题为二分答案,题意为从高到低依次给n个深度不同的水池和水管的流速(每个水管都一样),如果某一个池塘满了,那么 它只会向后面的的池塘溢水,问多长时间所有的池塘都能装满水和最后一个池塘什么时候装满水. ...

  2. 解题报告(十三)中国剩余定理(ACM / OI)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  3. 解题报告(五)组合计数(ACM / OI)超高质量题解

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  4. uscao 线段树成段更新操作及Lazy思想(POJ3468解题报告)

    线段树成段更新操作及Lazy思想(POJ3468解题报告) 标签: treequerybuildn2cstruct 2011-11-03 20:37 5756人阅读 评论(0) 收藏 举报  分类: ...

  5. 解题报告(十八)数论题目泛做(Codeforces 难度:2000 ~ 3000 + )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  6. 【解题报告系列】超高质量题单 + 题解(ACM / OI)超高质量题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我新写的超高质量的题解和代码,题目难度不 ...

  7. 解题报告(三)多项式求值与插值(拉格朗日插值)(ACM / OI)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  8. 解题报告(四)生成函数(ACM/ OI)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  9. 解题报告(八) prufer 序列与 Cayley 公式(ACM / OI)超高质量题解

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

最新文章

  1. qt打开数据库mysql数据库文件怎么打开_qt打开数据库mysql数据库文件
  2. iOS 使用FFmpeg实现视频H264编码
  3. angularjs的一点总结
  4. (转)Http协议经典详解
  5. 【数据结构学习之完全从零实现所有数据结构的代码编写之二】智能指针
  6. 我参与的一个项目总结
  7. android资源编译失败,在android studio中打开一个新项目时,Android资源编译失败
  8. Ubuntu禁用网卡步骤(重启依然生效)
  9. Hive数仓基本概念介绍
  10. mysql 忘记root密码的解决办法
  11. 移动端click事件延迟300ms到底是怎么回事,该如何解决?
  12. [病毒分析]熊猫烧香(上)初始分析
  13. android 远程连接电脑屏幕,Android安卓手机3389远程连接电脑桌面教程
  14. 量化投资学习——股票数据接口的汇总和整理
  15. vue的nxut框架生命周期触发两遍的问题
  16. 2019计算机就业形势图表分析,2019毕业生就业形势分析
  17. Leetcode力扣 MySQL数据库 1132 报告的记录II
  18. iphone二手机在哪里回收比较好(哪里回收的价格最高)
  19. 考研一年到底需要花多少钱?这个你必须要知道!!!
  20. WPF 几何图形之图形微语言命令

热门文章

  1. Jfrog:烂泥蛙安装
  2. 实体识别BERT-MRC论文阅读笔记
  3. jmeter巧用ForEach控制器
  4. 盘点2009年商场百货创意促销手段 秒杀当道
  5. 【CVPR2020】Detection in Crowded Scenes: One Proposal, Multiple Predictions笔记
  6. 项目使用ts辅助_使用新技术进行辅助项目
  7. [构造]Repetitions Decoding Codeforces1642D
  8. 跨考计算机面试英语自我介绍,2019考研复试面试英语自我介绍范文(2)
  9. qt mingw32编译项目报错:Nothing to be done for 'first'.
  10. 嘿嘿 抢到了iphone4