Codeforces Round #428 (Div. 2) B
B. Game of the Rows(贪心)
题意:
有k种颜色,每种有\(a_i\)个,将这k种颜色放在一个\(n * 8格子里\)
放置规则不能出现两个不同颜色在相邻的格子里,相邻的定义为在同一行
出现在(1,2),(3,4),(4,5),(5,6)或者(7,8) 这样都算相邻
\(1 <= n <= 10000\)
\(a_i <= 1000\)
$ \sum a_i <= 8 * n$
思路:
这道题贪心很不错,我是yy了很久了
贪心策略应该是让每种颜色尽量填满中间,再填满两边,
然后再把三个的放到中间,放不下就放到两边,
再把两个的放到中间,最后再填一个的
#include<bits/stdc++.h>
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ls (rt<<1)
#define rs (rt<<1|1)
using namespace std;
const int N = 1e6 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
int a[1100];
void can(int &x,int &y,int d){
if(!x || y < d) return ;
int res = min(x, y / d);
x -= res;
y -= res * d;
}
int main(){
int n,k;
cin>>n>>k;
int cnt2 = 2 * n,cnt4 = n;
for(int i = 0;i < k;i++){
scanf("%d",a + i);
}
for(int i = 0;i < k;i++){ ///首先尽量填满中间,然后填满两边
can(cnt4,a[i],4);
can(cnt2,a[i],2);
if(a[i] && (!cnt2 && !cnt4)) {
puts("NO");
return 0;
}
}
int c[4] = {0};
for(int i = 0;i < k;i++) c[a[i]]++;
int res3 = min(cnt4,c[3]);///把 3的 尽量放中间
c[3] -= res3;
cnt4 -= res3;
if(2 * c[3] > cnt2){ ///剩下的3 只能放两边了
puts("NO");
return 0;
}
cnt2 -= 2 * c[3];
int res2 = min(cnt4,c[2]); ///将 2 个的 放在中间的 剩余一个位置可以放其他
c[2] -= res2;
cnt4 -= res2;
if(2 * c[2] + c[1] <= res2 + cnt4 * 2 + cnt2) puts("YES");///计算所有能放一个的不同位置的个数
else puts("NO");
return 0;
}
Codeforces Round #428 (Div. 2) B的更多相关文章
- 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 | Codeforces Round #428 (Div. 2)
血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...
- 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) 最大 ...
- 【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) C】Journey
[Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...
- Codeforces Round #428 (Div. 2)A,B,C
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #428 (Div. 2)
终于上蓝名了,hahahahaha,虽然这场的 B 题因为脑抽了,少考虑一种情况终判错了,还是很可惜的.. B题本来过来1500个人,终判之后只剩下了200多个,真的有毒!!!! A - Arya a ...
随机推荐
- [vijos p1028] 魔族密码
描述 风之子刚走进他的考场,就……花花:当当当当~~偶是魅力女皇——花花!!^^(华丽出场,礼炮,鲜花)风之子:我呕……(杀死人的眼神)快说题目!否则……-_-###花花:……咦~~好冷~~我们现在要 ...
- 路由器基础配置之单臂路由实现vlan间通信
我们将以上面的拓扑图开始进行配置,目的为设置单臂路由实现vlan间通信,设置4个vlan,pc0,1,2为vlan10 pc3,4,5为vlan20:pc6,7,8为vlan30:server0,1为 ...
- python之微信自动发送消息
代码如下: from __future__ import unicode_literals from threading import Timer from wxpy import * import ...
- python pycharm2018开启debug模式
为什么需要开启DEBUG模式1.如果开启了DEBUG模式,那么在代码中如果抛出了异常,在浏览器的页面中可以看到具体的错误信息,以及具体的错误代码位置,方便开发者调试.2.如果开启DEBUG模式,那么以 ...
- [Bzoj2246]迷宫探险(概率+DP)
Description 题目链接 Solution 用三进制表示陷阱状态,1表示有害,2表示无害,0表示不知道 用\(f[S][i]\)表示状态为S时陷阱i有害的概率,这个可以预处理出 \(d[S][ ...
- Android stadio 插件推荐--ok gradle
今天发现了一个好玩的插件,对于想要知道依赖怎么写的同学很有帮助. 写这篇文章的意义在于,以后我忘了的话,可以自己在博客中找到. 上地址: https://github.com/scana/ok-gra ...
- echarts 地图的背景色和各省颜色配置以及地图饼图联动
myChart.on(ecConfig.EVENT.MAP_SELECTED, function (param) { var selected = param.selected; var str = ...
- ios交叉编译dylib
ios交叉编译dylib 因多个静态库,libes,libffmpeg,libmt. libpcap 使用不方便 在封装一层接口,生成动态库(c代码),由IOS app上层调用. IOS_BASE_S ...
- Android学习笔记(四)之碎片化Fragment实现仿人人客户端的侧边栏
其实一种好的UI布局,可以使用户感到更加的亲切与方便.最近非常流行的莫过于侧边栏了,其实我也做过很多侧边栏的应用,但是那些侧边栏的使用我 都不是很满意,现在重新整理,重新写了一个相对来说我比较满意的侧 ...
- 转载: keepalived工作原理和配置说明
转自:http://outofmemory.cn/wiki/keepalived-configuration keepalived是什么 keepalived是集群管理中保证集群高可用的一个服务软件, ...