Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
来源:互联网 发布:淘宝上的日亚礼品卡 编辑:程序博客网 时间:2024/06/06 19:27
传送门
//比赛的时候看错题了, 以为是相邻的座位要是不同的组来做, 关键是这样想还都能过样例. mmm.
//下来就把它补了. 既然要相邻的座位要是同一组的人做. 那么就只有4+2+1的做法. 所以我们就把数都分解成这种形式就OK了, (注意34也是算挨着的), 还要注意在算下一种做法时要加上之前的做法, 比如做2的时候, 要把剩余做4的再加上, 因为4的不能连续做两个的, 所以直接加上就好了. 最后做1的时候再加上之前做2,4,的剩余就好, 最后判断是否剩余>=0, 是就是YES, or NO.
AC Code
/** @Cain*/int a[105];void solve(){ int n,k; while(~scanf("%d%d",&n,&k)){ for(int i = 0;i<k;i++){ scanf("%d",&a[i]); } int sum1 = n; //一行做1个4个的. int sum2 = 2*n; //一行做2个2个的. for(int i = 0;i<k;i++){ int d = min(sum1,a[i]/4); sum1 -= d; a[i] -= d*4; } sum2+=sum1; //4个的不能连着做2个2个的. for(int i = 0;i<k;i++){ int d = min(sum2,a[i]/2); sum2 -= d; a[i] -= d*2; } int tmp = sum2+sum1; //一个的只能分开做. for(int i = 0;i<k;i++){ tmp -= a[i]; } if(tmp>=0) puts("YES"); else puts("NO"); }}
阅读全文
0 0
- Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
- Codeforce-839B Game of the Rows 思维
- 839B Game of the Rows(水,思维,贪心)
- codeforces#839 B Game of the Rows 思维,贪心
- Codeforces Round #428 (Div. 2) 839B. Game of the Rows(思维+贪心)
- B. Game of the Rows(贪心)
- CodeForces-839B Game of the Rows(思维、细节)
- Codeforces 839B Game of the Rows (贪心)
- Codeforces 839 B. Game of the Rows (贪心)
- Codeforces 839B Game of the Rows 贪心
- Game of the Rows codeforces 839B(贪心)
- codeforces #428 Div.2 B. Game of the Rows 贪心、思维
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- codeforces 839A 428 Div2 B Game of the Rows
- codeforces 839B Game of the Rows(思路题)
- CodeFroces 839B Game of the Rows(模拟)
- codeforces 839b 之 Game of the Rows
- 华为OJ-密码验证合格程序-牛客网
- 51nod 1515 明辨是非(合并并查集)
- Dbutils学习(介绍和入门)[转载]
- Android更改源码后编译错误unknown package name of class file
- Spring Bean的生命周期
- Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
- HBase常用命令及使用
- 编程小细节
- String、StringBuffer与StringBuilder之间区别
- dns的辅助和ddns
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- 关于Pyhton logging
- JavaScript趣味编程--仿微信飞机大战游戏--4.飞机重复往下
- pat:1016. 部分A+B (15)