CodeForces 297D Color the Carpet (脑补题)
题意
一个h*w的矩阵上面涂k种颜色,并且每行相邻格子、每列相邻格子都有=或者!=的约束。要求构造一种涂色方案使得至少有3/4的条件满足。
思路
脑补神题……自己肯定想不出来T_T……
官方题解:
This is my favorite problem in the contest :)
For k = 1 there is only one coloring so we just need to check the number of "E" constraints. When k ≥ 2, it turns out that using only 2color is sufficient to do so.
We will call the constraints that involves cells in different row "vertical constraints", and similar for "horizontal constraints".
First of all, we color the first row such that all horizontal constraints in row 1 are satisfied. We will color the remaining rows one by one.
To color row i, first we color it such that all horizontal constraints in row i are satisfied. Then consider the vertical constraints between row i and row i - 1. Count the number of satisfied and unsatisfied vertical constraints. If there are more unsatisfied constraints than satisfied constraints, flip the coloring of row i. Flipping a row means 2211212 → 1122121, for example.
If we flip the coloring of row i, all horizontal constraints in row i are still satisfied, but for the vertical constraints between row i and row i - 1, satisfied will becomes unsatisfied, unsatisfied will becomes satisfied. Therefore, one can always satisfy at least half the vertical constraints between row i and row i - 1.
Now for each row, all horizontal constraints are satisfied, at least half vertical constraints with the upper row are satisfied. It seems that we have got 75% satisfied in total. Unfortunately, the is exactly one more vertical constraints than horizontal constraints, which may make the fraction of satisfied constraints slightly less than 75%.
Luckily, we still have the all-satisfied first row. We can 'take' one satisfied horizontal constraints from it, and now we are guaranteed to have 75% satisfied constraints for row i. This also implies that the width of the table should be no less than the height of the table. If it is not in the case, rotate the table.
CodeForces 297D Color the Carpet (脑补题)的更多相关文章
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ...
- CodeForces 297A Parity Game (脑补题)
题意 一个01串,可以有两种操作:①在末尾添加parity(a):②删除开头的一个字符.其中parity(a),当串中1的个数为奇数时为1,偶数时为0.问某个01串是否可以通过若干操作变成另一个01串 ...
- Educational Codeforces Round 24 CF 818 A-G 补题
6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...
- Educational Codeforces Round 11 C hard process_补题——作为司老大的脑残粉
司老大当时教了一种姿势枚举连续K个0,说实话当时比赛写这题完全蒙了 纵然后来知道思路还是写了一段时间 真的是.. 题目大意 n长度的序列,由0 1构成 我们可以改变 k个0为1 求可以得到的最长连续1 ...
- Codeforces 补题记录
首先总结一下前段时间遇到过的一些有意思的题. Round #474 (Div. 1 + Div. 2, combined) Problem G 其实关键就是n这个数在排列中的位置. 这样对于一个排 ...
- 【cf补题记录】Codeforces Round #608 (Div. 2)
比赛传送门 再次改下写博客的格式,以锻炼自己码字能力 A. Suits 题意:有四种材料,第一套西装需要 \(a\).\(d\) 各一件,卖 \(e\) 块:第二套西装需要 \(b\).\(c\).\ ...
- 【cf补题记录】Codeforces Round #607 (Div. 2)
比赛传送门 这里推荐一位dalao的博客-- https://www.cnblogs.com/KisekiPurin2019/ A:字符串 B:贪心 A // https://codeforces.c ...
- Codeforces VP/补题小记 (持续填坑)
Codeforces VP/补题小记 1149 C. Tree Generator 给你一棵树的括号序列,每次交换两个括号,维护每次交换之后的直径. 考虑括号序列维护树的路径信息和,是将左括号看做 ...
- 2017河工大校赛补题CGH and 赛后小结
网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...
随机推荐
- Get started on your own KD 8 custom colorway
The 2009 Summer time Nike Basketball revealed the Cheap KD 8 and revealed three MVP-inspired colors ...
- springBoot 整合 RabbitMQ 的坑
1.Consumer raised exception, processing can restart if the connection factory supports it. Exception ...
- 下载.iso类型的软件如何安装
法一:这种类型的文件为镜像文件,一般默认在虚拟光驱上运行.通常的做法为: 安装Daemon Tools 虚拟光驱,可以打开CUE.ISO.CCD等这些虚拟光驱的镜像文件,并且将文件虚拟到光盘上使用.运 ...
- cocostudio 在VS模拟器中加载资源显示混乱问题
这个是由于cocos2d-x的资源是统一按照文件名管理的,所以游戏全局不能有重名. PS:所有用到的素材名字必须单一.
- python中的引用传递,可变对象,不可变对象,list注意点
python中的引用传递 首先必须理解的是,python中一切的传递都是引用(地址),无论是赋值还是函数调用,不存在值传递. 可变对象和不可变对象 python变量保存的是对象的引用,这个引用指向堆内 ...
- Apache 部署HTTPS
Apache 部署HTTPS 系统:Linux Centos 7.4 x64 应用:Apache 2.4.6 需要安装:mod_ssl 注:确认开启 Include conf/extra/httpd- ...
- 20145312 《Java程序设计》第四周学习总结
20145312 <Java程序设计>第四周学习总结 学习笔记 Chapter 6 6.1何为继承 1.定义:面向对象中子类继承父类,避免重复的行为定义. 6.1.1 继承共同行为 1.以 ...
- 20145211《网络渗透》msf辅助模块的应用
20145211<网络渗透>msf辅助模块的应用 一.实验准备 启用VB的kali,需要用到桥接,VMware桥接总是罢工…… 二.实验步骤 最好开桥接模式,要不然你就多开几个虚拟机(只要 ...
- SVN添加忽略目录
项目:Thinkphp 目录结构: Thinkphp |-- Common |-- Runtime |-- Home 忽略目标: Runtime 文件夹及下面所有文件 首先,需要忽略的目录必须没有加入 ...
- poj_2528 Mayor's posters (线段树经典题+离散化方法)
由于题面中给定的wall最大长度为10 000 000:若简单用线段树势必会超时. 而注意到题面中规定了输入海报的个数<=1000:因此不妨离散化,使得线段中叶节点仅含有1000个,那么线段最大 ...