CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)
血崩- -
/*
CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2)
注意
2 7
2 2 2 2 2 2 2
这组- -
*/
#include <bits/stdc++.h>
using namespace std;
int n, n2, n4, a[105], k;
bool solve()
{
n2 = 2*k;
n4 = k;
for (int i = 1; i <= n; i++)
{
if (a[i] >= 4 && n4)
{
int t = a[i]/4;
a[i] -= min(t, n4)*4;
n4 -= min(t, n4);
}
}
for (int i = 1; i <= n; i++)
{
if (a[i] >= 2 && n2)
{
int t = a[i]/2;
a[i] -= min(t, n2)*2;
n2 -= min(t, n2);
}
}
for (int i = 1; i <= n; i++)
{
if (a[i] && n2)
{
int t = a[i];
a[i] -= min(t, n2);
n2 -= min(t, n2);
}
}
int m2 = 0, m1 = 0, m3 = 0;
for (int i = 1; i <= n; i++)
if (a[i] == 3) m3++;
else if (a[i] == 2) m2++;
else if (a[i] == 1) m1++;
int sum = m3;
if (m1 <= m2)
{
sum += m1;
m2 -= m1;
sum += m2/3*2;
m2 %= 3;
sum += m2;
}
else
{
sum += m2;
m1 -= m2;
sum += (m1+1)/2;
}
if (sum > n4) return 0;
return 1;
}
int main()
{
scanf("%d%d", &k, &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
if (solve()) puts("YES");
else puts("NO");
}
CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)的更多相关文章
- CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...
- CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
- Codeforces 839B - Game of the Rows
839B - Game of the Rows 思路:先放4个的,然后再放2个的,最后再放1个的. 代码: #include<bits/stdc++.h> using namespace ...
- 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 839B Game of the Rows【贪心】
B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard ...
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- Codeforces Round #428 (Div. 2) D. Winter is here 容斥
D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
随机推荐
- 【转帖】lmbench的简单使用
https://www.cnblogs.com/mutong1228/p/10485840.html 下载地址 http://www.bitmover.com/lmbench/ tar -zxvf l ...
- python 异常的理解
对异常处理的意义在于,一些小概率异常且不是很严重的问题,如果没有处理,将直接导致程序停止,这显然不是我们想看到的,我们希望程序有一定的容错能力,能处理一些小异常. 但是我们要尽量避免使用try...e ...
- HTTP API自动化测试
重构:发现测试的价值 回到起点,测试要解决什么问题,为什么要做API自动化测试平台?做这个平台,不是为了满足老板的提倡全民自动化的口号,也不是为了浮夸的KPI,更不是宣传自动化可以解决一切问题,发现所 ...
- 怎样修改 VS Code 主题?
方法1. 点击左上角 File > Preferences > Color Theme. 方法2. 使用快捷键: Ctrl + K , Ctrl + T PS: 查询各种操作的快捷键可以 ...
- IExtenderProvider,c#组件扩展控件属性
[ProvideProperty("IsEnabled", typeof(LayoutControlItem)), ToolboxItemFilter("System.W ...
- javaIO——概述
以前看java书,都将IO作为一个大的章节甚至模块来编写,可见IO在java语言中的重要性. java的流按功能和处理的目标数据不同可以分为字节流和字符流.字符流处理的基本数据单元是字符:字节流处理的 ...
- 使用Vue CLI脚手架搭建vue项目
本次是使用@vue/cli 3.11.0版本搭建的vue项目 1. 首先确保自己的电脑上的Node.js的版本是8.9版本或者以上 2. 全局安装vue/cli npm install @vue/cl ...
- 有趣的"=="与"==="
console.log([]==![]);//true //"=="会进行类型转换,转换成统一类型进行比较 // !符号优于==,[]boolean值为TRUE,所以![]就是FA ...
- vue 实现textarea展示时自动换行
利用 v-html 展示 str.replace(/\n|\r\n/g, '<br>') 数据 完美解决
- ajax 传参数 java后台接收