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 ...
随机推荐
- 利用deadline_timer实现定时器Timer
// 类似QTimer的定时器 class Timer { typedef void(* handler)(); public: Timer() : m_millseconds() , m_timer ...
- js | JavaScript中数据类型转换总结
转载 在js中,数据类型转换分为显式数据类型转换和隐式数据类型转换. 1, 显式数据类型转换 a:转数字: 1)Number转换: 代码: var a = “123”; a = Number(a); ...
- 侯捷《C++面向对象开发》——动手实现自己的复数类
前言 最近在看侯捷的一套课程<C++面向对象开发>,刚看完第一节introduction之后就被疯狂圈粉.感觉侯捷所提及所重视的部分也正是我一知半解的知识盲区,我之前也写过一些C++面向对 ...
- JQuery制作网页—— 第四章JavaScript对象及初识面向对象
1.对象:在JavaScript中,所有事物都是对象,如字符串.数值.数组.函数等. JavaScript中的基本数据类型: number(数值类型) string(字符串类型) boolean ...
- 申请qq第三方登录 http://www.php20.com/forum.php?mod=viewthread&tid=29 (出处: 码农之家)
百度 qq互联 进入网站 按图中的步骤申请第三方登录即可 先申请成为开发者 审核通过后再继续操作 提交 后列表中会出现提交的申请. 状态为审核中,审核通过会得到下图. 点查看 红线后面就是appi ...
- hosts 文件的位置及作用
一.位置 1.Window系统位置 C:\Windows\System32\drivers\etc 2.Linux系统位置 /etc/hosts 二.作用 综述:Hosts文件中指定了域名和IP地址的 ...
- MPP(大规模并行处理)
1. 什么是MPP? MPP (Massively Parallel Processing),即大规模并行处理,在数据库非共享集群中,每个节点都有独立的磁盘存储系统和内存系统,业务数据根据数据库模型和 ...
- JS实现禁用滑动条但滑动条不消失的效果
//方法 //滑动条 // left: 37, up: 38, right: 39, down: 40, // spacebar: 32, pageup: 33, pagedown: 34, end: ...
- 通过aop添加日志管理
1.使用spring 的 aop 技术切到自定义注解上,所以先创建一个自定义注解类 import java.lang.annotation.*; @Target(ElementType.METHOD) ...
- 11.2,nginx负载均衡实验
Nginx负载均衡概述 Web服务器,直接面向用户,往往要承载大量并发请求,单台服务器难以负荷,我使用多台WEB服务器组成集群,前端使用Nginx负载均衡,将请求分散的打到我们的后端服务器集群中,实现 ...