博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 297D Color the Carpet (脑补题)
阅读量:4596 次
发布时间:2019-06-09

本文共 2015 字,大约阅读时间需要 6 分钟。

题意

一个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.


 

转载于:https://www.cnblogs.com/AbandonZHANG/p/4114109.html

你可能感兴趣的文章
制作自动化系统安装U盘
查看>>
python模块之xml.etree.ElementTree
查看>>
谷歌模拟
查看>>
【NOI2012】迷失游乐园
查看>>
postgresql 自定义排序
查看>>
任务就绪表OS_PrioGetHighest函数
查看>>
转:大灰狼的汇编视频教程笔记(下)
查看>>
javascript常见的几种事件类型
查看>>
关于大型网站技术演进的思考(八)--存储的瓶颈终篇(8)
查看>>
20+ 个很棒的 jQuery 文件上传插件或教程
查看>>
关于Struts2的多文件上传
查看>>
hosts学习整理
查看>>
github上的版本和本地版本冲突的解决方法
查看>>
ModalPopupExtender控件属性、功能
查看>>
js 工厂模式、简单模式、抽象模式
查看>>
扩展卡尔曼滤波(MRPT)
查看>>
如何解决Bluetooth系统设计的棘手问题
查看>>
加班两个星期做的一个小系统~(winform)
查看>>
排版系列1
查看>>
IDEA 生成 jar 包
查看>>