GCJ 2015-Qualification-B Infinite House of Pancakes 枚举,思路,误区 难度:3
https://code.google.com/codejam/contest/6224486/dashboard#s=p1
题目不难,教训记终生
题目给了我们两种操作:1 所有人都吃一个,简记为消除操作 2 所有人不吃,把一个人的煎饼分给另一个人或者新来的人,简记为分配
明显,分配操作分给新来的人更有利,并且分配操作应该在消除操作之前
现在就是怎么分配的问题:
之前错误了两次,因为误认为直接对半分效率更高,但是对于 1 9这组数据,明显是分成 1 3 3 3比分成1 4 5 更优
所以,枚举分配操作之后的最大煎饼数i,然后分别计算把每个数量大于i的盘子里分到i所需多少次操作tmp.答案取最小的tmp+i即可
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e3+3;
const int maxp=1e3+3;
int n;
int num[maxp]; int main(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
int T;
scanf("%d",&T);
for(int ti=1;ti<=T;ti++){
scanf("%d",&n);
memset(num,0,sizeof(num));
int ans=0;
for(int i=0;i<n;i++){
int tmp;
scanf("%d",&tmp);
num[tmp]++;
ans=max(tmp,ans);
}
int mx=ans;
for(int i=1;i<=mx;i++){
int tmp=0;
for(int j=i+1;j<=mx;j++){
tmp+=(j+i-1)/i*num[j]-num[j];
}
tmp+=i;
ans=min(tmp,ans);
}
printf("Case #%d: %d\n",ti,ans);
}
return 0;
}
GCJ 2015-Qualification-B Infinite House of Pancakes 枚举,思路,误区 难度:3的更多相关文章
- dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
Problem B. Infinite House of Pancakes Problem's Link: https://code.google.com/codejam/contest/6224 ...
- [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round
Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...
- [C++]Standing Ovation——Google Code Jam 2015 Qualification Round
Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...
- VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树
题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...
- codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题
B. Photo to Remember Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...
- Codeforces VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线线段树 求区间相同数的最小距离
D. Closest Equals Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/prob ...
- VK Cup 2015 - Qualification Round 1 A. Reposts [ dp DAG上最长路 ]
传送门 A. Reposts time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- hdu 5358 First One 2015多校联合训练赛#6 枚举
First One Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5371(manacher + 枚举)
Sample Input 1 10 2 3 4 4 3 2 2 3 4 4 Sample Output Case #1: 9 要求找出一段数字. 将其分成3部分,第①和第②部分成回文字串,第②和第 ...
随机推荐
- CSU 1802 小X的战斗力【拓扑dp】
题目链接 题意:n个人,每个人有一个能力值.给出m组关系A, B, 表示A的能力值大于B的能力值. 问:m组关系中是否有自相矛盾的?若不矛盾,问:第1个人在所有人的能力值中排名第几?有多少人的能力值的 ...
- java实现excel与mysql的导入导出
注意:编码前先导入poi相关jar包 1 /** * 读excel 到list * * @param file excel file * @param fields 字段数组 * @return * ...
- linux下,一些关于动态库的问题:
程序运行是加载动态库的几种方法: 第一种,通过ldconfig命令 ldconfig是一个动态链接库管理命令,为了让动态链接库为系统所共享,还需运行动态链接库的管理命令它,ldconfig命令通 ...
- POJ 3468 线段树裸题
这些天一直在看线段树,因为临近期末,所以看得断断续续,弄得有些知识点没能理解得很透切,但我也知道不能钻牛角尖,所以配合着刷题来加深理解. 然后,这是线段树裸题,而且是最简单的区间增加与查询,我参考了A ...
- 养成好的JAVA编码习惯
原文:http://blog.csdn.net/lifuxiangcaohui/article/details/25231027 最近的机器内存又爆满了,除了新增机器内存外,还应该好好review一下 ...
- 转:SQL的内连接与外连接
参考:http://www.cuiyongjian.com/post-130.html 在oracle的SQL语句常用的连接有内连接(inner join),外连接(outer join)等,内连接又 ...
- CSS3_边框属性之圆角的基本图形案例
一.正方形 div{ background:#F00; width:100px; height:100px;} 二.长方形 div{background:#F00;width:200px;heig ...
- eclipse如何调试(Debug)程序(zhuan)
http://jingyan.baidu.com/article/e6c8503c7e46b6e54f1a18c5.html ************************************* ...
- Selenium Grid 运行报错 Exception thrown in Navigator.Start first time ->Error forwarding the new session Empty pool of VM for setup Capabilities
Selenium Grid 运行报错 : Exception thrown in Navigator.Start first time ->Error forwarding the new se ...
- Unity5.3官方VR教程重磅登场-系列2
作者:王寒链接:https://zhuanlan.zhihu.com/p/20485529来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 欢迎继续我们的学习. 北京时间 ...