764D Timofey and rectangles[思维][染色]

来源:互联网 发布:linux怎么使用eclipse 编辑:程序博客网 时间:2024/06/05 21:07

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


题意:给定n个点对的坐标,分别表示以此两点位左下右上顶点的矩形,保证每个矩形的边长都是奇数。问相邻的矩形不同色,能否用四色染色,并输出每个颜色。

思路:根据四色定理,一定能够根据题意染色,即YES是一定的。 然后由于每个矩形的边长是奇数,现在我们只考虑左下角点的坐标x,y

若: x,y为奇数,边长是奇数,则对应的右上角的点坐标都是偶数,所以这样的矩形一定不会彼此相邻,可以涂颜色1。

若x为奇数,y为偶数,则对应右上角的点坐标横坐标是偶数,纵坐标是奇数,则这样的矩形只能与1颜色的矩形左右相邻,可涂颜色2.

若x为偶数,y为奇数,则与上面情况相反,与颜色1的矩形一定只能上下相邻,可涂颜色3.

若x为偶数y为偶数,可涂颜色4.

以上结果则符合题意。

代码:

#include <iostream>using namespace std;int x[500005], y[500005];int main(){    int n;    cin >> n;    for(int i = 0; i < n; ++i)    {        int a,b;        cin >> x[i] >> y[i] >> a >> b;    }    cout << "YES\n";    for(int i = 0; i < n; ++i)    {        if(x[i]<0)x[i]=-x[i];        if(y[i]<0)y[i]=-y[i];        if(x[i]%2==1&&y[i]%2==1)            cout << "1" << endl;        else if(x[i]%2==1&&y[i]%2==0)            cout << "2" << endl;        else if(x[i]%2==0&&y[i]%2==1)            cout << "3" << endl;        else            cout << "4" << endl;    }    return 0;}



0 0
原创粉丝点击