题干:

One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.

Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.

Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length

 The picture corresponds to the first example

Input

The first line contains single integer n (1 ≤ n ≤ 5·105) — the number of rectangles.

n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1 < x2 ≤ 109,  - 109 ≤ y1 < y2 ≤ 109), that means that points (x1, y1) and (x2, y2)are the coordinates of two opposite corners of the i-th rectangle.

It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.

Output

Print "NO" in the only line if it is impossible to color the rectangles in 4different colors in such a way that every two rectangles touching each other by side would have different color.

Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 ≤ ci ≤ 4) — the color of i-th rectangle.

Example

Input

8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1

Output

YES
1
2
2
3
2
2
4
1

题目大意:

一个无限大的平面被分为无数个小正方形格子,一些相连的格子们可以组成矩形。给出左下角和右上角的坐标来表示该矩形(比如给出 0 0 5 3 即代表坐标为(0,0)开始到(5,3)之间的所有格子组成的矩形)。矩形的长和宽只能是奇数,给出一些矩形的坐标表示,要求写程序为所有的矩形染色,相邻的矩形不可染同种颜色(题中已经给出所有的矩形没有两两相交的情况出现,且相邻的条件为存在大于0长度的公共边),如果存在染色方案则输出YES并且输出N个矩形的每种染色情况(如果存在多种情况输出任意一种即可),如果不存在染色方案则输出NO结束。

解题报告:

思路描述: 由于我们已知任意一个地图都4可着色,因此第一行一定永远是"YES"。关于着色方案,我们重点关注所有的边均为奇数的条件。

由于所有的边均为奇数,那么对于两个相邻的矩形,我们考虑其左下角的坐标:设其为A (x1,y1)和B (x2,y2);

  当A与B水平相邻时,即如下图所示(黄色为A,蓝绿色为B,其中(x1,y1)以及(x2,y2)分别表示红色的点和蓝色的点):

  我们可以看出对于任意两个相邻的矩形,其必有(x1与x2)或(y1与y2)的奇偶性不一致(因为所有矩形边长均为奇数),由于我们有4种染色方案(设为1 2 3 4),因此我们可以构造其染色情况为

[(x%2+2*(y%2))+4]%4+1(其中x和y表示该矩形左下角坐标),即可保证相邻的矩形中没有同色的情况(因为该染色情况下同色当且仅当x与y的奇偶性一致)。

AC代码:

#include<iostream>
#include<cmath>
using namespace std;
int main() {int n, a, b, c, d;ios::sync_with_stdio(false);cin >> n;cout <<"YES"<<endl;while(n--) {cin>>a>>b>>c>>d;int tmp = abs(a) % 2 + 2 * (abs(b) % 2);cout << tmp + 1 << endl;}return 0;
}

总结:

[(x%2+2*(y%2))+4]%4+1这个公式也可以,这两种构造的方式虽然结果不同但是都符合题意。注意负数取模问题!

【CodeForces - 764D】Timofey and rectangles (四色定理 + 找规律 + 构造)相关推荐

  1. CodeForces - 603C Lieges of Legendre(博弈+找规律)

    题目链接:点击查看 题目大意:首先给出n堆石子和一个k值,两人轮流按照规则操作,不能操作的一方即为失败,每一次都有两种操作: 从任意一堆石子中取走一个石子 任选一堆偶数个的石子,将其转换成k堆x/2的 ...

  2. Codeforces Round #242 (Div. 2)C(找规律,异或运算)

    一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...

  3. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

  4. CodeForces - 768B Code For 1(找规律)

    题目链接:http://codeforces.com/problemset/problem/768/B点击打开链接 B. Code For 1 time limit per test 2 second ...

  5. CodeForces - 1339E Perfect Triples(打表找规律)

    题目链接:点击查看 题目大意:序列 s 是一个无限数列,现在给出构造方法: 选择三个数 a b c ,将其依次加到序列 s 的最后面,三个数需要满足: a b c 在序列 s 中均未出现过 a b c ...

  6. CodeForces - 1245C Constanze's Machine(思维+找规律)

    题目链接:点击查看 题目大意:给出一个字符串s,该字符串是由一台坏掉的打字机生成的,坏掉的打字机会将m打成nn,将w打成uu,问现在给出字符串s,其原本的字符串有多少种可能性 题目分析:因为m会变成n ...

  7. CodeForces - 1110C-Meaningless Operation(打表找规律)

    Can the greatest common divisor and bitwise operations have anything in common? It is time to answer ...

  8. 拼多多 2020校招 多多的排列函数(找规律 构造)

    数列 {An} 为N的一种排列. 例如N=3,可能的排列共6种: 1 2 3 4 5 6 1, 2, 3 1, 3, 2 2, 1, 3 2, 3, 1 3, 1, 2 3, 2, 1 定义函数F: ...

  9. Codeforces Round #715 (Div. 1) B. Almost Sorted 找规律

    传送门 文章目录 题意: 思路: 题意: 思路: 找规律yydsyydsyyds. 一看没什么想法,所以打了个表,好家伙,不打不知道,一打不得了,下面是n=6n=6n=6的符合要求的情况: 不难发现, ...

最新文章

  1. 常见加密算法分类,用途,原理以及比较
  2. java语言 文件上传,java中实现文件上传的方法
  3. java每秒限流_java限流工具类
  4. 一文解读:如何从 0 到 1 打造小程序爆款裂变
  5. LLBLGen 关于类型转换
  6. 阅读笔记-你的灯还亮着吗?
  7. 2020年11月3日 星期二 工作日志 github登陆不了了,晕
  8. 数值的整数次方(剑指offer面试题11)
  9. Linux查 ssh端口号
  10. 企业级Web报表工具告诉你财务要做哪些数据分析
  11. CR渲染器全景图如何渲染颜色通道_CR渲染如何设置渲染AO图和材质通道?
  12. 新闻人物言论自动提取
  13. Holt-Winters模型分析及时间序列预测
  14. (NCRE网络技术)网络系统结构与设计的基本原则-知识点
  15. 【数据结构笔记】将两个递增的有序链表合并为一个递增的有序链表
  16. 如何用Excel做一个战斗模拟器(一)升级经验表
  17. 百度富文本编辑器引入问题
  18. 2013总结——告别页游,迎接手游
  19. php版本kms,使用 AWS KMS 加密和解密 AWS SDK for PHP 数据密钥 - 适用于 PHP 的 AWS 开发工具包...
  20. Communication error with Jack server

热门文章

  1. 复盘二进制的习题(2)
  2. c语言 用一维数组存储二叉树,用一维数组存储二叉树时,总是以前序遍历顺序存储结点。( ? )...
  3. 工厂方法模式_1天1个设计模式——工厂方法模式
  4. 计算机软考有学历限制吗,软考中级职称申请积分还需要学历吗?
  5. 高仿人人android梦想版终极源码发送,人人Android客户端梦想版发布
  6. android 自定义spnner弹出框,PopupWindow,ListView实现自定义Spinner
  7. ESlint静态代码检测工具安装
  8. 自定义hibernate validation注解
  9. if-else多级嵌套,输入3/4/5个数寻找最大值(太多了容易乱!!!)
  10. go java性能_服务端I/O性能大比拼:Node、PHP、Java和Go