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 ...
随机推荐
- Maven - 配置镜像仓库
默认仓库的配置(全球中央仓库): 可以打开maven的安装目录/conf/settings.xml文件,配置镜像,找到如下一段配置,这里默认没有配置任何镜像,但是有一个被注释的配置范例: id: 镜像 ...
- Shell学习——数值运算
在Bash shell中,可以利用let.(( )).[]执行基本的算术操作,在高级操作时,使用expr和bc两个工具1.let[root@client02 ~]# no1=4[root@client ...
- 【c学习-3】
---恢复内容开始--- #include<stdio.h> int main(){ ]={,,,,}; ; ;i<=;i++){ printf("%d\n",a ...
- MyCat实现数据库与数据库之间的读写分离
一.Mycat的安装准备: 1.jdk:要求jdk必须是1.7及以上版本 2.Mysql:推荐mysql是5.5以上版本 3.Mycat: Mycat的官方网站: http://www.mycat.o ...
- iptables v1.3.5: multiple -d flags not allowed错误已解决
今天写了一条iptables的规则 iptables -t filter -A INPUT -s 192.168.192.0/24 -d 192.168.192.140 -p tcp -dport 2 ...
- mybatis在where中比较复杂的判断
<if test="param.applicationStateInNumber != null and param.applicationStateInNumber != ''&qu ...
- [BZOJ1899]Lunch 午餐(DP)
[BZOJ1899] 首先有个很贪心的思路,吃饭时间长的最先打饭为最优,所以开始先排个序 然后考虑DP,我们不需要知道某个人在哪个对,只要关注总的时间就行了 肯定需要一维表示当前同学编号,还需要表示某 ...
- Eclipse字体修改
第一步: 第二步: 第三步: 第四步: 第五步: 第六步:
- P1297 网线切割
P1297 网线切割 题目描述 Wonderland居民决定举行一届地区性程序设计大赛.仲裁委员会志愿负责这次赛事并且保证会组织一次有史以来最公正的比赛.为此,所有参赛者的电脑和网络中心会以星状网络连 ...
- shell编程——参数传递
1.Linux Shell参数引用 $0 这个程式的执行名字$n 这个程式的第n个参数值,n=1..9$* 这个程式的所有参数$# 这个程式的参数个数$$ 这个程式的PID$! 执行上一个背景指令的P ...