[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 ...
随机推荐
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1003 HDU 6152 Friend-Graph (模拟)
题目链接 Problem Description It is well known that small groups are not conducive of the development of ...
- 通过cordova将vue项目打包为webapp
准备工作:需要之前配置好vue-cli脚架构,安装好cordova环境.下面开始对vue.js项目进行打包,打包环境为Android. 可以看下我的github:https://github.com/ ...
- UIAutomation Diagram
- ogg使用语句
create tablespace ogg datafile '/oracle/oradata/DRMT/ogg01.dbf' size 50M autoextend on; edit params ...
- 利用__attribute__((section()))构建初始化函数表【转】
转自: https://mp.weixin.qq.com/s?__biz=MzAwMDUwNDgxOA==&mid=2652663356&idx=1&sn=7797629530 ...
- git-定制属于你的log格式
软件版本: 操作系统:ubuntu10.04 内核版本:Linux version 2.6.32-36-generic git 版本:git version 1.7.0.4 1. ...
- centos7-sar工具的安装过程及其简单应用
一.sar工具安装 1.进入yum配置文件目录: cd /etc/yum.repos.d/ 2.vi CentOS-Base.repo命令创建文件CentOS-Base.repo 文件内容见网页:ht ...
- CentOS 7 中 Docker 的安装
CentOS 7 中 Docker 的安装 Docker 软件包已经包括在默认的 CentOS-Extras 软件源里.因此想要安装 docker,只需要运行下面的 yum 命令: [root@loc ...
- centos7安装lamp
一.准备工作 1. 下载并安装CentOS7.2,配置好网络环境,确保centos能上网,可以获取到yum源. centos7.2的网络配置: vim /etc/sysconfig/network ...
- VS里属性窗口中的生成操作释义
生成操作:无,编译 ,内容 ,嵌入的资源... 如果是类.cs文件,就得编译之后你才能使用的.如果是txt,excel 这种文件,就属性内容或者资源文件了. 内容(Content) - 不编译该文件, ...