codeforces 839B Game of the Rows(思路题)
来源:互联网 发布:三星s7解网络锁工具 编辑:程序博客网 时间:2024/05/16 02:49
题目链接
Game of the Rows
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5},{5, 6} or {7, 8}.
思路:因为中间的4个位置比较特殊,可以坐2+1,或者是4,或者是1+1(这个太浪费位置,下下策), 旁边的2个位置能坐2,或者1个人;
先统计这k个队伍的能分成几个4,几个2,几个1(我用x4,x2,x1表示),这里的1一定是要占2个位置的。
首先要保证n个位置够坐(x4*4+x2*2+x1*2<=8*n),然后要保证中间的4连座(共有n个)不能是2+2的情况,每个4人座一定要坐的有1,或者是坐的有4,即x1+x4>=n。(让4和1先去坐中间)
但还有一个样例
2 7
2 2 2 2 2 2 2 答案:YES
如果没有8*n - (x4*4+x2*2+x1*2)>0 那么我就有多余的位置了,那么我就可以让一个2变成两个1,然后再判断x1+x4>=n;
AC代码:
#include <stdio.h>#include <iostream>#include <string>#include <string.h>using namespace std;int main(){ int n,k; scanf("%d%d",&n,&k); int ans1=0,ans2=0,ans4=0,a; while(k--) { scanf("%d",&a); if(a>=4) { ans4+=a/4; a=a-a/4*4; } if(a>=2) { ans2++; a-=2; } if(a) ans1++; } int x=n*8-ans4*4-ans1*2-ans2*2; if(x>=0&&ans4+ans1>=n-x) printf("YES\n"); else printf("NO\n");}
- codeforces 839B Game of the Rows(思路题)
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- Codeforces 839 B. Game of the Rows (贪心)
- Codeforces 839B 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(思维、细节)
- codeforces 839b 之 Game of the Rows
- codeforces#839 B Game of the Rows 思维,贪心
- Game of the Rows codeforces 839B(贪心)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心,补题)
- B. Game of the Rows(贪心)
- 839B Game of the Rows(水,思维,贪心)
- Game of the Rows CodeForces
- Game of the Rows CodeForces
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- PCB一些设置记录
- RCC初始化学习
- 通过Ajax方式上传文件
- 按键中断总结
- STM32串口USART通信总结
- codeforces 839B Game of the Rows(思路题)
- DMA实验总结
- C/C++时间函数
- I2C_24c02实验
- 开始新的征程~~~~从第一个python 的机器学习实验开始~~~~~SVM实验
- sysTick系统定时器
- MOSFET学习
- 晶体管电路设计学习笔记(一)
- 增强输出的电路