[GCJ2017R2]Fresh Chocolate
题目大意:
有n个团和很多盒糖,每个团中人数不一定相同,每盒糖中都有p颗糖。
现在要给每个团发糖,要求每个人都要发到糖,只有一盒糖发完后才能发下一盒糖。
发糖的顺序可以任意安排,问经过合理安排后,最多能让几个团吃到新开的糖。
思路:
分类讨论+贪心。
讨论p的不同取值。
对于p=2时,如果人数是偶数,就肯定能满足,如果是奇数就两两配对,满足其中的一组。
对于p=3时,如果刚好能被3整除,就肯定能满足,剩下余数为1的和余数为2的配对,再剩下来的每三组能满足一组。
对于p=4时,如果刚好能被3整除,就肯定能满足,剩下余数为2的尽量和自己配对,余数为1的尽量和3配对。
剩下来1和3的只会有一种,然后和2配对即可。
一开始考试时全想到了,不过p=3的时候,对于1和2配对的情况,当时没想清楚,以为能满足两组。
p=4的时候对于剩下的情况打表,似乎也打挂了。
然后就只拿了30分。
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
int main() {
int T=getint();
for(register int t=;t<=T;t++) {
int n=getint(),p=getint();
if(p==) {
int ans=,cnt=;
for(register int i=;i<=n;i++) {
if(getint()&) {
cnt++;
} else {
ans++;
}
}
printf("Case #%d: %d\n",t,ans+((cnt+)>>));
continue;
}
if(p==) {
int cnt1=,cnt2=,ans=;
for(register int i=;i<=n;i++) {
const int x=getint();
if(!(x%)) ans++;
if(x%==) cnt1++;
if(x%==) cnt2++;
}
if(cnt1==cnt2) {
ans+=cnt1;
}
if(cnt1<cnt2) {
ans+=cnt1+(cnt2-cnt1)/;
if((cnt2-cnt1)%) ans++;
}
if(cnt2<cnt1) {
ans+=cnt2+(cnt1-cnt2)/;
if((cnt1-cnt2)%) ans++;
}
printf("Case #%d: %d\n",t,ans);
continue;
}
if(p==) {
int cnt1=,cnt2=,cnt3=,ans=;
for(register int i=;i<=n;i++) {
const int x=getint();
if(!(x&)) ans++;
if((x&)==) cnt1++;
if((x&)==) cnt2++;
if((x&)==) cnt3++;
}
ans+=cnt2>>;
cnt2&=;
int min=std::min(cnt1,cnt3);
ans+=min;
cnt1-=min;
cnt3-=min;
if(cnt2&&cnt1>=) {
ans++;
cnt1-=;
cnt2=;
}
if(cnt2&&cnt3>=) {
ans++;
cnt3-=;
cnt2=;
}
if(cnt2) {
ans++;
} else {
ans+=(cnt1+)>>;
ans+=(cnt3+)>>;
}
printf("Case #%d: %d\n",t,ans);
continue;
}
}
return ;
}
[GCJ2017R2]Fresh Chocolate的更多相关文章
- 数据结构作业——Fresh Meat(优先队列)
Fresh Meat Description 我们故事的主角是屠夫扒鸡,起初屠夫扒鸡只是一个佣兵,他先去拜了太上老君为师,学了一技能肉钩,凭着一技肉钩驰骋决斗场,达到一段以后到阿尔伯特那里偷学了二技能 ...
- Big Chocolate
Big Chocolate 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19127 Big Chocolat ...
- Dividing a Chocolate(zoj 2705)
Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...
- hdu----(4301)Divide Chocolate(状态打表)
多校综合排名前25名的学校请发送邮件到HDUACM@QQ.COM,告知转账信息(支付宝或者卡号) Divide Chocolate Time Limit: 2000/1000 MS (Java/Oth ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #310 (Div. 1) C. Case of Chocolate set
C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...
- codeforces 678C C. Joty and Chocolate(水题)
题目链接: C. Joty and Chocolate time limit per test 1 second memory limit per test 256 megabytes input s ...
- CodeForces 689C Mike and Chocolate Thieves (二分+数论)
Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...
- Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索
E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...
随机推荐
- Spring Boot中对log4j进行多环境不同日志级别的控制
之前介绍了在<Spring boot中使用log4j记录日志>,仅通过log4j.properties对日志级别进行控制,对于需要多环境部署的环境不是很方便,可能我们在开发环境大部分模块需 ...
- 【CF343D】 Water Tree(树链剖分)
题目链接 树剖傻逼题,练练手好久没写树剖了. 查询忘记\(pushdown\)抓了好久虫.. 全文手写,一遍过... #include <cstdio> const int MAXN = ...
- 【leetcode 简单】第四十一题 Excel表列序号
给定一个Excel表格中的列名称,返回其相应的列序号. 例如, A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ...
- 仿360影视网站模板html
链接:http://pan.baidu.com/s/1mhIkV4s 密码:9wgq
- weblogic 包里面有中文文件名 会报错
目前:没有解决,只要有中文启动就报错 http://bbs.csdn.net/topics/10055670 http://www.2cto.com/os/201406/311394.html
- 【Python学习】使用BeautifulSoup解析HTML
对于一个最简单的爬虫结构的代码是这样的. 也就是抓取出整个页面,然后创建一个BeautifulSoup对象. from urllib.request import urlopen from bs4 i ...
- [Leetcode] Combination Sum 系列
Combination Sum 系列题解 题目来源:https://leetcode.com/problems/combination-sum/description/ Description Giv ...
- Postgres中tuple的组装与插入
1.相关的数据类型 我们先看相关的数据类型: HeapTupleData(src/include/access/htup.h) typedef struct HeapTupleData { uint3 ...
- 从LabVIEW到C++
前言 最近一段时间一直没有更新,一方面是时间精力的问题(PS:懒癌犯了),另一方面是小黑大部分的时间都在学习C++相关知识,恶补了许多的知识(从大学C语言水平强制拔高了一段). 本文谈谈自己近期的一些 ...
- Oracle创建WM_CONCAT函数
Oracle创建WM_CONCAT函数 WM_CONCAT这个函数会出错,所以从 11g开始.官方不认可 WM_CONCAT.然后就没这个函数了, 下面就是创建WM_CONCAT这个函数的步骤 第一步 ...