题目大意:
  有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. Oracle笔记之序列(Sequence)

    Oracle中序列是一种数据对象,可以视为一个等差数列,我们自增就是一个遍历这个数列的过程,可以取当前值,也可以将当前值自加n后返回,Sequence与表没有太大的关系,有的时候如果表的主键是数值类型 ...

  2. php常用函数——数组函数

    php常用函数——数组函数

  3. django框架<二>

    django框架:   Models 1.基本创建 Django提供了一个抽象层("Model")的构建和管理Web应用程序的数据. Django使用一种新的方式,即:关系对象映射 ...

  4. linux用户修改用户shell

    要拒绝系统用户登录,可以将其shell设置为/usr/sbin/nologin或者/bin/false # usermod -s /usr/sbin/nologin username 或者 # use ...

  5. caffe Python API 之Accuracy

    net.acc = caffe.layers.Accuracy(net.fc3,net.label) 输出: layer { name: "acc" type: "Acc ...

  6. 关于"轉淚點"与"轉捩點"

    经常看台湾偶像剧或台湾综艺节目的人,一定听过"转泪点"这个词,虽然我一直不知道这三个字具体是怎么写, 但其意思很容易明白,就是"转折点"的意思.今天无聊在看凤凰 ...

  7. ACM——【百练习题备忘录】

    1. 在做百练2807题:两倍时,错将判断语句写成 a/b ==2,正确写法是:a == b*2 因为C/C++int型做除法时自动舍入,如:5/2 == 2,但是 5 =/= 2*2. 2. 在做百 ...

  8. Nginx1.8.1 编译扩展https

    nginx无缝编译扩展https 本贴只限用于通过编译安装的nginx,如果用的是yum源安装请卸载后参见 http://www.cnblogs.com/rslai/p/7851220.html 安装 ...

  9. Oracle数据库(64位) 及 PLSQL(64位)的组合安装【第一篇】

    目前PC端普遍使用64位操作系统,64位操作系统在性能上比32位更佳,但是兼容性上则不如32的操作系统,Oracle提供了64和32两种版本,而PLsql工具则只有32位,在这篇文章详细的讲述了如何在 ...

  10. HDU 3342 Legal or Not(拓扑排序判断成环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 题目大意:n个点,m条有向边,让你判断是否有环. 解题思路:裸题,用dfs版的拓扑排序直接套用即 ...