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部分,第①和第②部分成回文字串,第②和第 ...
随机推荐
- poj1556The Doors
链接 枚举两点 若不和任何线段相交 建边为dis(i,j) floyd求最短路 #include <iostream> #include<cstdio> #include< ...
- Oracle数据库内置函数
--ORACLE内置函数:单行函数,集合函数--1.绝对值,取余,判断数据正负函数,SELECT ABS(100),ABS(-100),ABS('100') FROM DUAL;SELECT MOD( ...
- Android 上千张图片的列表滑动加载
一般项目中图片加载用的比较多的是ImageLoader 但是需求自己配置一些参数 上手有些复杂 对于手机图库中有上千张图片需要加载时 一个使用性能很好的库Glide可以解决 效果图如下 滑动非常流畅 ...
- Nginx基本配置备忘
原文:http://www.open-open.com/lib/view/open1482477873078.html Nginx 配置 在了解具体的Nginx配置项之前我们需要对于Nginx配置文件 ...
- OpenCV图像处理中常用函数汇总(1)
//俗话说:好记性不如烂笔头 //用到opencv 中的函数时往往会一时记不起这个函数的具体参数怎么设置,故在此将常用函数做一汇总: Mat srcImage = imread("C:/Us ...
- js树目录结构
jstree https://www.jstree.com/demo/ treejs http://www.treejs.cn/v3/demo.php#_206
- cocos2dx从入门到精通课程
一.移动开发基础 二.cocos2dx跨平台理论 三.cocos2dx框架 四.cocos2dx内存管理 五.cocos2dx的事件与消息机制 六.cocos2dx的定时器 七.cocos2dx的渲染 ...
- hdu 2102
简单的3维BFS 大写的YES和NO,这心粗的....唉 #include<iostream> #include<cstdio> #include<queue> u ...
- Text Justification [LeetCode]
Problem Description:http://oj.leetcode.com/problems/text-justification/ Note: Just be careful about ...
- 118. 119. Pascal's Triangle -- 杨辉三角形
118. Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...