Codeforces 839 B. Game of the Rows-贪心
1 second
256 megabytes
standard input
standard output
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 nrows, 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}.
A row in the airplane
Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.
Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively.
The second line contains k integers a1, a2, a3, ..., ak (1 ≤ ai ≤ 10000), where ai denotes the number of soldiers in the i-th group.
It is guaranteed that a1 + a2 + ... + ak ≤ 8·n.
If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).
You can choose the case (lower or upper) for each letter arbitrary.
2 2
5 8
YES
1 2
7 1
NO
1 2
4 4
YES
1 4
2 2 1 2
YES
In the first sample, Daenerys can place the soldiers like in the figure below:
In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.
In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.
In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).
题意:主要的就是不同的军队不能挨着坐。
所以能把4个位置坐满的话就先坐满,然后考虑2个位置的。
对于4个人来说就是坐在中间的4个位置,对于3个人来说也是坐在中间,但是可以有一种操作,把3个人分成2个人和1个人,
然后是考虑2个人和1个人的,都是坐在两边的位置或者中间坐一个2个人坐一个1个人,或者中间坐2个1个人的。
最近太zz了,一开始想的太麻烦了,忘记了还有比较大小这种操作了。。。
代码:
#include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
for(int i=;i<k;i++)
scanf("%d",&a[i]);
int sum1=n;
int sum2=*n;
for(int i=;i<k;i++){
int d=min(sum1,a[i]/);
sum1-=d;
a[i]-=d*;
}
sum2+=sum1;
for(int i=;i<k;i++){
int d=min(sum2,a[i]/);
sum2-=d;
a[i]-=d*;
}
int tmp=sum2+sum1;
for(int i=;i<k;i++)
tmp-=a[i];
if(tmp>=)printf("YES\n");
else printf("NO\n");
}
return ;
}
Codeforces 839 B. Game of the Rows-贪心的更多相关文章
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- Codeforces 839B Game of the Rows - 贪心
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldie ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- Educational Codeforces Round 7 E. Ants in Leaves 贪心
E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connec ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- Codeforces Round #180 (Div. 2) B. Sail 贪心
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
随机推荐
- 这是我见过最厉害的--智能代码生成器、html+js+底层+sql全都有、瓦特平台
1:直接上图.图片有点多.我就没全部上传了. (demo.使用方法.数据库bak)下载:http://pan.baidu.com/s/1ntE5bDn 起源: 之前有好多人问我代码生成器的源码.我发了 ...
- 关于在虚拟机上安装iOS所遇到的问题
先配一张成功的图片: 要想实现上图所示的,就要安装 unlocker206, 安装完unlocker206 不用改里面的内容!!!看到**经验上说还要改内容,结果我试了很多次,根本不行,其实问题不在改 ...
- ul中li元素横向排列且不换行
ul { white-space: nowrap; } li { display: inline-block; } white-space 属性设置如何处理元素内的空白. normal 默认. ...
- 浅谈传输层协议TCP和UDP
在当今因特网的层次结构中,传输层的协议主要有两种,其一为Transmission Control Protocol,即TCP:其二为User Datagram Protocol,即UDP. 1.TCP ...
- 选择MariaDB的压缩数据引擎TokuDB
业务运用场景 数据基本不用update, 不频繁的范围查询 数据存储量较大(为以后准备) 选择占用磁盘较小的db 业务对数据库插入操作频繁,为避免影响其它业务,需要将直播业务的DB 独立出来,选择另外 ...
- React跨域问题解决
https://segmentfault.com/q/1010000012732581 非跨域问题报错 -rpccorsdomain="http://localhost:3000" ...
- HDU 4101 Ali and Baba (思路好题)
与其说这是个博弈,倒不如说是个搜索.这题思路不错,感觉很难把情况考虑周全. 在地图外围填充一圈0,两次BFS,第一次从-1点出发,把从-1到达的0点以及包围0的那一圈石头标记出来.如下图: 1 1 1 ...
- CentOS程序 开机启动设置与chkconfig命令学习
CentOS设置程序开机启动的方法: 1.启动命令添加到/etc/rc.d/rc.local 文件中, 如: vim /etc/rc.d/rc.local #!/bin/sh # # This scr ...
- 多线程 线程组 ThreadGroup
package org.zln.thread; import java.util.Date; /** * Created by sherry on 000024/6/24 22:30. */ publ ...
- 【BZOJ 5048 塌陷的牧场】
Time Limit: 25 Sec Memory Limit: 256 MBSubmit: 77 Solved: 34[Submit][Status][Discuss] Description ...