Codeforces Round #395 (Div. 2)D. Timofey and rectangles

D. Timofey and rectangles
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 x1y1x2 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 4 different 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

题意:给出一些边相接触的矩形,用四种颜色里面的一种给矩形上色,问是否存在一种方案让所有边接触的矩形颜色

都不同。有的话打印出来每个矩形的颜色,没有的话打印NO。

思路:题意中有个很奇怪的条件,边长为奇数。今天想了一上午才想明白。

对于一个坐标点(x, y) 如果x是奇数,那么加奇数长度的值就是偶数,如果是偶数加奇数长度值就是奇数。

用左下角点表示一个矩形位置,对于某个点只有四种状态 (奇数,奇数)(偶数,偶数)(奇数,偶数)(偶数,奇数)之一,

而边接触的矩形位置则是其它3种之一,而颜色只有4种,所以一种状态给一种颜色,什么情况都会有解。

printf("%d\n", (2*(x%2) + y%2)+1);

官方题解给的是上面的这种表达式,其实就是先把4种状态用00 01 10 11编码,x是高位,y是低位,2×x就是让x的值

存在高位。这样得到0 1 2 3,颜色是1 2 3 4所以要加1。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值