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) 最大 ...
随机推荐
- 【转】iis7下站点日志默认位置
本文转自:http://www.cnblogs.com/mincyw/p/3425468.html 在iis6时,通过iis管理器的日志配置可以找到站点日志存储的位置. 但是在iis7下,iis管理器 ...
- Django(一)安装启动
Django下载/启动 1.下载安装 pip install django 或者 压缩文件下载地址:https://github.com/django/django/releases python s ...
- varnish CLI管理
命令:varnishadm [-t timeout] [-S secret_file] [-T address:port] [-n name] [command [...]] ./varnishadm ...
- android 一个SQLite数据库多个数据表的基本使用框架 (带demo)
android 一个SQLite数据库多个数据表(带demo) 前言 demo演示 一.搭建 二.建立实体类 三.建立数据库操作类 ...
- bzoj2152 聪聪可可 (树形dp)
大意: 给定树, 随机选两点, 求两点距离是3的倍数的概率. 树形dp入门水题, 枚举每个点作为lca时的答案即可. #include <iostream> #include <qu ...
- pat L2_004
一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点, 其左子树中所有结点的键值小于该结点的键值: 其右子树中所有结点的键值大于等于该结点的键值: 其左右子树都是二叉搜索树. 所谓二叉搜索 ...
- TCP协议探究(二):超时与重试
1 概述 TCP提供可靠的运输层. 可靠性保证之一:确认从另一端收到的数据. 但数据和确认都有可能会丢失.TCP通过在发送时设置一个定时器来解决这种问题. 如果当定时器溢出时还没有收到确认,它就重传该 ...
- 初学java3 条件判断
三目运算符 条件? 正确结果:错误结果 if判断 单一条件判断 if(条件){ }else{ } 多种条件判断 if(){ }else if(){ } ... else{ } switch判断 swi ...
- 集合源码阅读——ArrayList
ArrayList 关键点: >>扩容每次扩容1.5倍 >>modcount的作用 >>ArrayList的父类AbstractList的成员变量 >> ...
- oracle wm_concat函数用法
在Oracle中使用wm_concat(column)可以实现字段的分组合并,逗号分隔.