题目大意:
  有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的更多相关文章

  1. 数据结构作业——Fresh Meat(优先队列)

    Fresh Meat Description 我们故事的主角是屠夫扒鸡,起初屠夫扒鸡只是一个佣兵,他先去拜了太上老君为师,学了一技能肉钩,凭着一技肉钩驰骋决斗场,达到一段以后到阿尔伯特那里偷学了二技能 ...

  2. Big Chocolate

    Big Chocolate 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19127 Big Chocolat ...

  3. Dividing a Chocolate(zoj 2705)

    Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...

  4. hdu----(4301)Divide Chocolate(状态打表)

    多校综合排名前25名的学校请发送邮件到HDUACM@QQ.COM,告知转账信息(支付宝或者卡号) Divide Chocolate Time Limit: 2000/1000 MS (Java/Oth ...

  5. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  6. 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/ ...

  7. codeforces 678C C. Joty and Chocolate(水题)

    题目链接: C. Joty and Chocolate time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. CodeForces 689C Mike and Chocolate Thieves (二分+数论)

    Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...

  9. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

随机推荐

  1. html中插入其他html,并实现动态效果!

    <html> <body> 倒计时开始...... <span id="s1">888</span> <!--在html中先做 ...

  2. perl6 一个猜测密码的注入

    use HTTP::UserAgent; my $ua = HTTP::UserAgent.new; my $r = HTTP::Request.new; my $c = HTTP::Cookies. ...

  3. 在Ubuntu上安装搜狗输入法

    1.进入搜狗输入法官网 2.下载Linux版本,选择64bit 下载 3.等待下载的同时,进行系统配置 进入系统设置->语言支持->进行更新(需要输入登录密码)->在键盘输入法系统选 ...

  4. 安装mysql驱动之 mysqlclient 出现的报错处理(ubuntu16.04)

    首先 更新软件! sudo apt-get update 然后尝试安装mysqlclient,报错 后执行下面的步骤 安装mysql驱动之 mysqlclient 出现的报错信息处理 报错1: OSE ...

  5. bash: composer: command not found

    下载composer到本地:curl -sS https://getcomposer.org/installer | php 移动至系统服务:sudo mv composer.phar /usr/bi ...

  6. Webcollector应用(一)

    webcollector是一个开源的Java网络爬虫框架.最近的爬虫改用java写了,对这一周的工作进行简要总结.对于内部机制了解不深入,主要侧重在应用. 一.环境搭建 需要安装一个webcollec ...

  7. 【转载】python-协程

    转载自:廖雪峰的官方网站 协程,又称微线程,纤程.英文名Coroutine. 协程的概念很早就提出来了,但直到最近几年才在某些语言(如Lua)中得到广泛应用. 子程序,或者称为函数,在所有语言中都是层 ...

  8. 20165301 2017-2018-2 《Java程序设计》第六周学习总结

    20165301 2017-2018-2 <Java程序设计>第六周学习总结 教材学习内容总结 第七章:常用实类 String类 构造String对象 常量对象 String对象 Stri ...

  9. Copy List with Random Pointer——技巧

    A linked list is given such that each node contains an additional random pointer which could point t ...

  10. DNS使用TCP还是UDP?

    DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.下面将介绍DNS分别在什么情况下使用这两种协议. TCP与UDP简介    TCP ...