Codeforces 839B
来源:互联网 发布:通话数据统计软件 编辑:程序博客网 时间:2024/06/05 04:31
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}.
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.
题意如上所示。
题解:贪心,首先很容易想到对于每组中有4个,肯定占中间最长的即3456,之后处理2,最后处理1。做这种题发现不能乱模拟,必须思路情绪.不然很难1A。
#include <bits/stdc++.h>using namespace std;int main(){ //std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int n, k, num; int four, two, one; four = two = one = 0; scanf("%d%d",&n,&k); for(int i = 1;i <= k;i ++) { scanf("%d",&num); four += num / 4, num %= 4; two += num / 2, num %= 2; one += num; } int Four = n, Two = n * 2, One = 0; if(four >= Four) four -= Four, Four = 0; else Four -= four, four = 0; if(four > 0) two += four * 2, four = 0; else Two += Four, One += Four, Four = 0; if(two > 0) { if(Two >= two) Two -= two, two = 0; else two -= Two, Two = 0; if(Two > 0) One += Two, Two = 0; } else { One += Two, Two = 0; } puts(One >= 2 * two + one ? "YES" : "NO"); return 0;}
- Codeforces 839B
- Codeforces 839B (implement)
- codeforces 839B(模拟)
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- 快速幂(基础)
- Android开发笔记-音频录制/播放&音频
- 彻底解决python3与python2的版本冲突(window版)
- ~动态内存管理~
- ueditor jar包的作用
- Codeforces 839B
- stdout和stderr重定向
- 多线程3-池
- 程序员的一生--类
- ccf认证模板生成系统90分运行超时
- hdu 6127极角排序
- Effective Modern C++ Item 4
- html5实现滚动文字
- win8 com surrogate占用cpu过高