Google Code Jam Qualification Round 2015 Problem B. Infinite House of Pancakes
来源:互联网 发布:大麻种子 淘宝 编辑:程序博客网 时间:2024/06/04 20:05
Problem
At the Infinite House of Pancakes, there are only finitely many pancakes, but there are infinitely many diners who would be willing to eat them! When the restaurant opens for breakfast, among the infinitely many diners, exactly D have non-empty plates; the ith of these has Pi pancakes on his or her plate. Everyone else has an empty plate.
Normally, every minute, every diner with a non-empty plate will eat one pancake from his or her plate. However, some minutes may be special. In a special minute, the head server asks for the diners' attention, chooses a diner with a non-empty plate, and carefully lifts some number of pancakes off of that diner's plate and moves those pancakes onto one other diner's (empty or non-empty) plate. No diners eat during a special minute, because it would be rude.
You are the head server on duty this morning, and it is your job to decide which minutes, if any, will be special, and which pancakes will move where. That is, every minute, you can decide to either do nothing and let the diners eat, or declare a special minute and interrupt the diners to make a single movement of one or more pancakes, as described above.
Breakfast ends when there are no more pancakes left to eat. How quickly can you make that happen?
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each consists of one line with D, the number of diners with non-empty plates, followed by another line with D space-separated integers representing the numbers of pancakes on those diners' plates.
Output
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the smallest number of minutes needed to finish the breakfast.
Limits
1 ≤ T ≤ 100.
Small dataset
1 ≤ D ≤ 6.
1 ≤ Pi ≤ 9.
Large dataset
1 ≤ D ≤ 1000.
1 ≤ Pi ≤ 1000.
Sample
In Case #1, one diner starts with 3 pancakes and everyone else's plate is empty. One optimal strategy is:Minute 1: Do nothing. The diner will eat one pancake.
Minute 2 (special): Interrupt and move one pancake from that diner's stack onto another diner's empty plate. (Remember that there are always infinitely many diners with empty plates available, no matter how many diners start off with pancakes.) No pancakes are eaten during an interruption.
Minute 3: Do nothing. Each of those two diners will eat one of the last two remaining pancakes.
In Case #2, it is optimal to let the diners eat for 2 minutes, with no interruptions, during which time they will finish all the pancakes.
In Case #3, one diner starts with 4 pancakes and everyone else's plate is empty. It is optimal to use the first minute as a special minute to move two pancakes from the diner's plate to another diner's empty plate, and then do nothing and let the diners eat for the second and third minutes.
解析
显然先把饼分好,然后再开始吃是最优的策略。暴力枚举饼数量的上界,如果比这个标准多就分给另一个空盘的人。然后所有时间里求个极小值。
#include<cstdio>#include<algorithm>using namespace std;int D,P[1010];long long find(int x){long long ans=0;for(int i=1;i<=D;i++)if(P[i]>0) ans+=(P[i]-1)/x;return ans+x;}void work(){scanf("%d",&D);for(int i=1;i<=D;i++)scanf("%d",&P[i]);sort(P+1,P+1+D);long long ans=0x3f3f3f3f3f3f3f3fLL;for(int i=P[D];i>0;i--)ans=min(ans,find(i));printf("%lld\n",ans);}int main(){freopen("B2.in","r",stdin);freopen("B.out","w",stdout);int T; scanf("%d",&T);for(int i=1;i<=T;i++){printf("Case #%d: ",i);work();}}
- Google Code Jam 2015 Qualification Round: Problem B. Infinite House of Pancakes
- Google Code Jam Qualification Round 2015 Problem B. Infinite House of Pancakes
- [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round
- google code jam 2015 B. Infinite House of Pancakes
- Google Code Jam 2010 Qualification Round 2012 Problem B && C
- Google Code Jam 2015 Qualification Round: Problem A. Standing Ovation
- Google Code Jam 2015 Qualification Round: Problem C. Dijkstra
- Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
- Google Code Jam Qualification Round 2014 Problem B. Cookie Clicker Alpha 题解
- Google Code Jam 2014 Qualification Round:Problem B. Cookie Clicker Alpha
- Google Code Jam 2012 Qualification Round. Problem D. Hall of Mirrors
- Google Code Jam 2014-Qualification Round-Problem C. Minesweeper Master
- Google Code Jam 2014 Qualification Round:Problem A. Magic Trick
- Code Jam 2017 Qualification Round Problem B. Tidy Numbers
- Google Code Jam 2014 Qualification Round 2014 A B D
- Google Code Jam Round 1A 2015 Problem B. Haircut
- Google Code Jam 2015 Round 1A: Problem B. Haircut
- Google Code Jam 2015 Qualification Round: Problem D. Ominous Omino 【Small Input】
- Adobe 官方公布的 RTMP 规范
- 第26讲—项目4—本月有多少天
- 在Ubuntu 14.04 64bit上安装字体管理器font-manager
- win8.1 rJAVA和Rwordseg安装
- JXL操作Excel
- Google Code Jam Qualification Round 2015 Problem B. Infinite House of Pancakes
- Swift学习开始啦--基础(一)
- opencv2.4.9(10)配置
- SSH 中的分层结构
- 快登——一键快捷登录工具
- IIS 下配置PHP
- 2015年移动Web/HybridApp开发技能列表
- MFC的记事本
- xml写入