题意

一个h*w的矩阵上面涂k种颜色,并且每行相邻格子、每列相邻格子都有=或者!=的约束。要求构造一种涂色方案使得至少有3/4的条件满足。

思路

脑补神题……自己肯定想不出来T_T……


官方题解:

297D - Color the Carpet

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.


 

最新文章

  1. Linux中grep搜索用法
  2. 工业串口和网络软件通讯平台(SuperIO 2.1)更新发布
  3. js鼠标滚轮滚动图片切换效果
  4. 超好用的网页栅格化工具: GridGuide
  5. Maven安装与配置
  6. 关于解压覆盖IIS文件后,新的文件不具备权限导致DMS系统无法正常运行
  7. Web安全测试学习笔记(Cookie&Session)
  8. vim 使用记录
  9. 【学习笔记】【C语言】类型说明符
  10. 一个鼠标键盘控制两台甚至多台主机的方法--Synergy
  11. Xcode5.1离线下载安装及使用iOS5模拟器进行开发调试的方法
  12. 【三支火把】---C文件学习
  13. HTML新元素
  14. ContextSwitchDeadlock was detected Message(读取注册表时出现).
  15. 2016年如何选择 Linux 发行版
  16. IE8下的项目在IE11下某些功能无法实现的问题
  17. backup-mysql.sh
  18. python结合shell脚本实现简单的日常集中巡检
  19. FineReport数据库连接(oracle+plsql)(1)
  20. Flask入门第一天

热门文章

  1. IOS 此时无法安装XXX
  2. vim中快速定位到某行以及快捷删除多行
  3. ActiveRecord多数据库配置
  4. PKU 3020 Antenna Placement(拆点+最小边覆盖)(最大匹配)
  5. 解决wordcloud导出图片不清楚
  6. Linux查看本机登陆用户信息(w、who、last和lastlog命令)
  7. java中内存泄露和内存溢出
  8. vue2.0中配置文件路径
  9. Spring Aop之Cglib实现原理详解
  10. flume从log4j收集日志输出到kafka