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

来源:互联网 发布:淘宝客导购网站有哪些 编辑:程序博客网 时间:2024/05/23 00:03

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
80 0 5 32 -1 5 0-3 -4 2 -1-1 -1 2 0-3 0 0 55 2 10 37 -3 10 24 -2 7 -1
output
YES12232241
当时c没思路,简单的看了一下d,四色原理。。。。并且没注意那个边肯定是奇数的条件。。。。。。。然后不会。。就去怼c了,一直也没回来看d

其实不难。。因为边长肯定是奇数,所以只有左下点坐标全奇,全偶或一奇一偶这四种情况互相之间才有可能有边相邻

全奇和全偶之间就不说了,

全奇和一奇一偶,举个例子

x偶y奇

1 1 4 4 

4 1 3 2 

x奇y偶

1 1 4 4

1 4 2 5

全偶和一奇一偶

x偶y奇

0 0 3 3 

0 3 1 4

x奇y偶

0 0 3 3

3 0 4 1

#include<stdio.h>#include<math.h>int x[500005],y[500005];int main(){int n,i,a,b;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d %d %d %d",&x[i],&y[i],&a,&b);printf("YES\n");for(i=0;i<n;i++){if(x[i]&1&&y[i]&1)printf("1\n");else if(x[i]&1&&!(y[i]&1))printf("2\n");else if(!(x[i]&1)&&y[i]&1)printf("3\n");else printf("4\n");}return 0;}

这次做的很差,光怼c还没怼出来,d也直接弃了,

看题一定要看清题意!!!不要遗漏!!!

无论什么题,都要思考至少五分钟在决定是否跳过!!

好好学英语。。。。。。。。。。。。。。。。。。。。。。。。。。


0 0
原创粉丝点击