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) 最大 ...
随机推荐
- 基于DBMS_METADATA.GET_DDL函数批量导出索引的创建语句
/* 首先要说的DBMS_METADATA.GET_DDL是个好函数呀!新项目不知道哪个缺心眼建的同构库,只是见了表结构,并没有健非主键外的索引,领导让追加一版,以前只是会用视图拼sql创建,今天有学 ...
- servlet获取checkbox的值出现选中的值为on。问题所在。。。
<form action="/Http/request06" method="post"> 用户名:<input type="tex ...
- 关于typescript中的枚举你需要知道这些
数字枚举 数字枚举,即枚举里所有属性的值都是数字类型,先看这段代码: enum Colors { Red, Blue, Yellow } console.log(Colors.Red) console ...
- 剑指offer19:按照从外向里以顺时针的顺序依次打印出每一个数字,4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.
1 题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印 ...
- 微信小程序 基本介绍及组件
创建项目 微信开发工具深入介绍 https://developers.weixin.qq.com/miniprogram/dev/devtools/devtools.html 基本项目目录 1. 配置 ...
- 【数据结构】P1449 后缀表达式
[题目链接] https://www.luogu.org/problem/P1449 [题目描述] 所谓后缀表达式是指这样的一个表达式:式中不再引用括号,运算符号放在两个运算对象之后,所有计算按运算符 ...
- k8s之网络插件flannel及基于Calico的网络策略
1.k8s网络通信 a.容器间通信:同一个pod内的多个容器间的通信,通过lo即可实现; b.pod之间的通信:pod ip <---> pod ip,pod和pod之间不经过任何转换即可 ...
- Spring MVC 探讨DispatcherServlet
先上DispatcherServlet的运行流程图(request processing):
- C#基础知识 (转)
https://www.cnblogs.com/zhouzhou-aspnet/articles/2591596.html(原文地址) 本文是一个菜鸟所写,本文面向的人群就是像我这样的小菜鸟,工作一年 ...
- WPf ObservableCollection异步调用问题
当ObservableCollection列表被UI线程占用时,如果在异步线程中调用ObservableCollection,会弹出以下异常: private void Button1_OnClick ...