Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心)
来源:互联网 发布:chrome的json插件 编辑:程序博客网 时间:2024/06/18 18:06
题意很简单了,给n个部队的士兵安排飞机座位,使得不同部队的士兵不会坐在邻座,如图所示, {1, 2}, {3, 4}, {4, 5}, {5, 6} {7, 8}都是邻座。给出部队数和每个部队的人数以及飞机座位的排数,问有没有合法的方案。
重点应该就是{4,5}这个座位也是相邻的,所以安排位置要有策略.
1.每个部队有4人以上的,每4人安排到中间的四个座位上(直到没有中间的座位或安排完)
2.每个部队剩余的大于2人以上的,每两人安排到一个两侧的座椅对上(直到安排完或者座位用完)
3.每个部队中若还有剩余的2人以上的,每两人安排到中间的4座中的一排中(两队不能邻座,所以一队坐一排的左边两个或者右边两个)。(直到中间排用完或者安排完)
4.若还有部队有剩余两人以上的,就得拆开坐在上一步使用的4座中的没被坐的座椅对的靠走道的位置。
5.每个部队剩余单人也是得1人占用一个座椅对。
以如上方式安排,若能安排完则YES,否则NO。
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int n, k;int a[105];int need[105];int main(){ int dan = 0;//每个部队剩余的单人 bool f = 1; scanf("%d%d",&n, &k); int zhong = n;//中间4座的数量 for (int i = 0; i < k; i++){ scanf("%d", &a[i]); need[i] = a[i] / 2; if (a[i] % 2)dan++; int kk = need[i] / 2; if (zhong >= kk){ need[i] -= kk * 2; zhong -= kk; } else{ need[i] -= zhong * 2; zhong = 0; } } int lef = 2*n;//两边剩余的座位对数 int sum = 0;//还需安排的士兵对数 for (int i = 0; i < k; i++){ sum += need[i]; } if (lef >= sum){ lef -= sum; sum = 0; int fi = lef + zhong * 2; if (fi >= dan)printf("YES\n"); else printf("NO\n"); return 0; } else{ sum -= lef; lef = 0; if (zhong< sum){ sum-=zhong; int now=sum*2+dan; if(zhong>=now)printf("YES\n"); else printf("NO\n"); return 0; } int kkk = zhong * 2 - sum; if (kkk >= dan)printf("YES\n"); else printf("NO\n"); return 0; } return 0;}
阅读全文
0 0
- 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 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) Game of the Rows (思维)
- codeforces #428 Div.2 B. Game of the Rows 贪心、思维
- CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces 839 B. Game of the Rows (贪心)
- B. Game of the Rows(贪心)
- Codeforces 428(div 2)B. Game of the Rows(思维题)
- Codeforces 839B Game of the Rows (贪心)
- Codeforces 839B Game of the Rows 贪心
- codeforces#839 B Game of the Rows 思维,贪心
- jQuery选择器(2)
- Codeforces 839 B. Game of the Rows (贪心)
- 【jzoj5251】【GDOI2018模拟8.11】【决战】【状态压缩动态规划】
- MongoDB Capped集合 使用注意事项
- C语言入门:奇数值节点链表
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心)
- 【字符串】寻宝之旅
- UVA10791MinimumSumLCM
- hd 1102
- Linux文件查找利器 locate & find
- spring4.2+struts2.5+jdbc实例-PIMS(二)
- hdu 6096
- Python入门(二)
- CSU1978: LXX的图论题