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) 最大 ...
随机推荐
- docker中启动2个mysql实列
一.mac环境安装docker容器 在docker官网中下载docker容器,地址:https://www.docker.com/products/docker-desktop 具体安装教程及设置网络 ...
- 使用jbc查询数据封装成对象的工具类
适用于获取Connection对象的util package com.briup.myDataSource; import java.io.FileReader; import java.io.Inp ...
- 剑指offer42:数组和一个数字S,输出两个数的乘积最小的
1 题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小的先输出. ...
- Python多线程VS多进程
- 【第一季】CH09_FPGA多路分频器设计
[第一季]CH09_FPGA多路分频器设计 在第七节的学习中,笔者带大家通过一个入门必学的流水灯实验实现,快速掌握了VIVADO基于FPGA开发板的基本流程.考虑到很多初学者并没有掌握好Vivado ...
- MyBatis 示例-主键回填
测试类:com.yjw.demo.PrimaryKeyTest 自增长列 数据库表的主键为自增长列,在写业务代码的时候,经常需要在表中新增一条数据后,能获得这条数据的主键 ID,MyBatis 提供了 ...
- DateTime.TryParse 日期时间字符串验证
DateTime applicationDatetime = new DateTime(); bool applicationDate = DateTime.TryParse("2019-0 ...
- Jmeter4.0---- jmeter逻辑控制器(16)
1.说明 逻辑控制器可以帮助用户控制Jmeter的测试逻辑,特别是何时发送请求.逻辑控制器可以改变其子测试元件的请求执行顺序. 2.逻辑控制器 (1)如果(if)控制器 用法一: 审核人员,数据分为 ...
- Install CUDA 6.0 on Ubuntu 14.04 LTS
Ubuntu 14.04 LTS is out, loads of new features have been added. Here are some procedures I followed ...
- VisualStudio2015 安装
环境:Win10 64位 推荐安装顺序 IIS > Sqlserver > Asp.Net 启动安装程序(出现Logo后需要等待1到2分钟),选择安装路径(注意不要出现中文路径) 勾选需求 ...