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部分,第①和第②部分成回文字串,第②和第 ...
随机推荐
- 01 Developing Successful Oracle Applications
varchar2 类型定义时, 个人认为应该选择byte 类型, 即 varchar2(20), oracle 支持的最大的字符串是 varchar2(4000), 同时, 个人认为, 当你定义一个v ...
- DDL和DML的定义和区别
DML(Data Manipulation Language)数据操纵语言: 适用范围:对数据库中的数据进行一些简单操作,如insert,delete,update,select等. DDL(Data ...
- Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数
格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: /** * 获取指定时间到格林威治时间的秒数 ...
- 将一堆石子分成多堆——Multi-SG 游戏
这类博弈只需要记住一点,一个由多个游戏组成的游戏sg值为这多个游戏的sg值异或和. 也就是所有对一整个nim游戏它的sg值即为每一小堆的sg的异或和. hdu 5795 这题就是可以选择把一堆石子分成 ...
- spring mvc获取request HttpServletRequest
1.最简单的方式(注解法) 2. 直接的方法,参数中添加(response类似) package spittr.web; import static org.springframework.web.b ...
- jQuery封装函数
//1,插件命名:jQuery.插件名.js 为拉避免和其他库的冲突// //2,自定义插件尽量避免使用$ 如果非要使用$就一定要将jQuery传递进去,//写在最后加一个小括号写jquery ;结束 ...
- iOS开发 判断字符串是不是网址
- (BOOL)isUrlString { NSString *emailRegex = @"[a-zA-z]+://.*"; NSPredicate *emailTest = [ ...
- Mysql有两种存储引擎:InnoDB与Myisam
http://www.cnblogs.com/kevingrace/p/5685355.html
- Sqoop安装配置及数据导入导出
前置条件 已经成功安装配置Hadoop和Mysql数据库服务器,如果将数据导入或从Hbase导出,还应该已经成功安装配置Hbase. 下载sqoop和Mysql的JDBC驱动 sqoop-1.2.0- ...
- arithmetic
字典序算法 http://www.cnblogs.com/darklights/p/5285598.html 字典排序(lexicographical order)是一种对于随机变量形成序列的排序方法 ...