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部分,第①和第②部分成回文字串,第②和第 ...
随机推荐
- [转载] 理解RESTful架构
原文: http://www.ruanyifeng.com/blog/2011/09/restful.html 理解RESTful架构 作者: 阮一峰 日期: 2011年9月12日 越来越多的人开 ...
- Android网络编程系列 一 TCP/IP协议族
在学习和使用Android网路编程时,我们接触的仅仅是上层协议和接口如Apache的httpclient或者Android自带的httpURlconnection等等.对于这些接口的底层实现我们也有必 ...
- Android自动接听&挂断电话(包含怎么应对4.1以上版本的权限检
一 前言 这两天要研究类似白名单黑名单以及手势自动接听的一些功能,所以呢,自然而然的涉及到怎么自动接听/挂断电话的功能了.对于自动接听这一块,android4.1版本及其以上的版本和之前的版本处理逻 ...
- go语言中间的循环
在Go语言中只有很少的几个控制结构,它没有while或者do-while循环. 但是它有for.switch.if.而且switch接受像for那样可选的初始化语句.下面来认识一下他们 一.if语句 ...
- 传大附件在iis7以上的设置
IIS7下设置上传附件大小的限制,下载附件限制问题 最近项目中涉及到一个上传附件的问题,项目在本地运行时上传无论多大的附件都是没有问题,但是一旦部署到服务器上以后上传的附件超过一定大小就上传不成功 ...
- Kafka的配置文件详细描述
在kafka/config/目录下面有3个配置文件: producer.properties consumer.properties server.properties (1).producer.pr ...
- git 10.8
git clone xxxx.git生成一个本地的文件夹acd agit checkout -b abcgit checkout mastergit pull然后数据全部由更新 但是是远程的更新 不能 ...
- phalcon: router规则与解析,已经生成router的链接地址
本人采用的是假分模块(目录),通过命名空间来进行模块分组的,非官方分组,所以在router是都会加上 namespace 信息,你也可适当的参考: 前提: /** * 注册命名空间 */ $loade ...
- Office 多版本共存
1 32位共存 假如已经安装了Office 2003(必定是32位的),那么安装 32位Office 2010 时会出现如下错误: 图1.1 解决办法: 1.将下述三个注册表项导出到文件2003A.r ...
- 如何在腾讯云快速构建一个Wordpress个人站点
版权声明:本文由贺嘉原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/175 来源:腾云阁 https://www.qclou ...