CF-839B
B. Game of the Rowstime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputIf 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.
Examplesinput2 2
5 8outputYESinput1 2
7 1outputNOinput1 2
4 4outputYESinput1 4
2 2 1 2outputYESNoteIn 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).
题意:
有n排座位,有k组 每组有a[i]人,问能否使不同组的人都不相邻。
先将a[i]分为4 2 1,先放4的部分,再2,再1。
AC代码:
#include<bits/stdc++.h>
using namespace std; int a[]; int main(){
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
for(int i=;i<k;i++){
cin>>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 temp=sum1+sum2;
for(int i=;i<k;i++){
temp-=a[i];
}
if(temp>=){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
return ;
}
CF-839B的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
随机推荐
- Jquery获取iframe中的元素
iframe与父页面之间相互获取元素的方法: 1.从父页面中获取iframe页面中的元素: 用法: $(window.frames["iframe_include_adverse" ...
- Can a GridView have a footer and header just like ListView?
Aquick question: In ListView I use this code: list.addHeaderView(headerView); How to deal with it wh ...
- MySQL 事务1
本人应用的MySQL的版本为:5.6.22
- python 基础 1.5 数据类型(二)--列表
一.python 数据类型序列---列表 1.列表是可变型的数据类型.列表里边的元素是可变的,可以增加,可以删除. 2.列表(list)是处理一组有序项目的数据结构,即可以在列表中存储一个序列的项 ...
- _THROW 何解?
在看/usr/include/........中.h头文件对函数接口的定义时,总是能看到在函数结尾加一个_THROW,一时不明白这是什么意思,而且对于有些POSIX和ISO C不承认或未明确的定义的函 ...
- 【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法
[BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=10000 ...
- EasyPlayerPro(Windows)流媒体播放器开发之接口设计
EasyPlayerPro(windows)接口说明如下: EasyPlayerPro_Open 说明:打开一个媒体流或者媒体文件进行播放,同时返回一个 player 对象指针 参数说明: fileU ...
- (转)浅析三层架构与MVC模式的区别
MVC模式介绍: MVC全名是Model ViewController,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用于组织代码用一种业务逻辑和数据 ...
- save create
其中 create 和 create!就等於 new 完就 save 和 save!,有無驚嘆號的差別 在於 validate 資料驗證不正確的動作,無驚嘆號版本會回傳布林值(true 或 false ...
- IOS UITableView reload 刷新某一个cell 或 section
通常刷新整个列表 我们都使用[self.tableView reloadData]; 有的时候,有变化更新的只是某一行 row 或者是某个section 所以只更新这一行就好了 //一个section ...