CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows
来源:互联网 发布:sql case when null 编辑:程序博客网 时间:2024/06/03 17:46
题目:
B. Game of the Rows
题解:
1.先将人分为4,3,2,1;将4,3填入中间4连座,然后将2填入两旁2连座,统计剩余座位和2,1的人
2.若2连座有剩余,则只需将超出4连座的4,3以及1尝试填入2;
3.若2连座不足,则将2,1填入4连座,最好为1个四连座填一个1和一个2.
4,若能填完所有人则为YES,否则为NO。
AC代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <string>#include <cstring>#define maxn 100000 + 10#define For(a,b) for(int i = a; i < b; i++)typedef long long LL;int n,k;using namespace std;int main(){ cin >> n >> k; int t; int j = 0; int x=0,y=0,z=0; for(int i = 0; i < k; i++) { scanf("%d",&t); x += t/4; if(t%4 == 1) y++; if(t%4 == 3) x++; if(t%4 == 2) z++; } int nn = n - x; int nm = n*2 - z; // cout << nn <<" "<< nm<< " " << x << " "<< y << " "<< z << endl; if(nm < 0) { if(nm+y>0) if((nn-min(nm*(-1),y))*2 >= y+nm) printf("YES\n"); else printf("NO\n"); else if(nm+y < 0) if((nn-min(nm*(-1),y))*3 >= (y+nm)*(-1)*2) printf("YES\n"); else printf("NO\n"); else { if(nn-y >= 0) printf("YES\n"); else printf("NO\n"); } } else if(nn *2 + nm >= y) printf("YES\n"); else printf("NO\n"); return 0;}
阅读全文
0 0
- CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) Game of the Rows (思维)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) 839B. Game of the Rows(思维+贪心)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- Codeforces Round #428 (Div. 2) B. Game of the Rows (思维)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心,补题)
- Codeforces Round #428 (Div. 2)-贪心&模拟-B. Game of the Rows
- codeforces #428 Div.2 B. Game of the Rows 贪心、思维
- 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
- Game of the Rows CodeForces
- Game of the Rows CodeForces
- Android XML布局文件解析过程源码解析
- sqlserver性能优化
- 泛类弄的声明
- PHP面试篇之基础0
- (CSU
- CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows
- spark集群
- 推荐排序
- css实现两个div并排等高
- ==和equals()
- validateRequest=false 可以禁用请求验证
- Java_观察者模式(Observable和Observer)
- java中简单二叉树的实现
- eclipse集成go语言环境及实例hello world