[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 ...
随机推荐
- Islands and Bridges(POJ2288+状压dp+Hamilton 回路)
题目链接:http://poj.org/problem?id=2288 题目: 题意:求Hamilton 路径权值的最大值,且求出有多少条权值这么大的Hamilton路径. 思路:状压dp,dp[i] ...
- 零基础讲解JavaScript函数
一 JavaScript函数1 什么是函数 函数是一组代码(指令)的集合,通常用来完成某个单一的功能.(书的目录和章节,电视剧剧集的名称等)2 为什么要使用函数 2.1 把复杂程序划分成不同的功能 ...
- 宋牧春: Linux设备树文件结构与解析深度分析(2) 【转】
转自:https://mp.weixin.qq.com/s/WPZSElF3OQPMGqdoldm07A 作者简介 宋牧春,linux内核爱好者,喜欢阅读各种开源代码(uboot.linux.ucos ...
- screen命令使用方法【转】
在linux的环境中,我们想要在后台持续运行一些脚本,但是又因为关闭这个tty的话,脚本就会中断,这个时候我们就需要screen这个工具的帮助啦! 基础 1 首先先查看下否则有这个工具.如果运行s ...
- windows安装React Native开发运行环境
React Native是什么 React Native是facebook开源的一个用于开发app的框架.React Native的设计理念:既拥有Native (原生) 的用户体验.又保留React ...
- ireport报表制作, 通过节点、产品类型来判断,当该节点审核通过之后,报表相对应的审核意见及签名 显示相对应的内容
1.代码① (与本内容相关的代码:7~36) 以下类似 $P{P_XXXX} :均为页面端的传入参数 select so.sale_order_no as sale_order_ ...
- 网页查看源码中<div>的含义
代码如下: /** HTML转义 **/ String s = HtmlUtils.htmlEscape("<div>hello world</div><p&g ...
- (五)Spring 对事务的支持
第一节:事务简介 满足一下四个条件: 第一:原子性: 第二:一致性: 第三:隔离性: 第四:持久性: ------------------------------------------------- ...
- csu 1592(区间DP)
1592: 石子归并 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 356 Solved: 148[Submit][Status][Web Board ...
- gentoo emerge unable to sync
gentoo emerge unable to sync Author: Tubo After setting SYNC to customized URL: SYNC="rsync://m ...