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
![](https://i-blog.csdnimg.cn/blog_migrate/8ea4dc9b92ee47bb72e34ded88b94c17.png)
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.
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.
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
YES 1 2 2 3 2 2 4 1
题意:
给出一些不相交的边长为奇数的n个矩形,每个矩形用x1,y1,x2,y2,描述,(x1,y1),(x2,y2)分别是左下角和右上角的点,每个矩形之间可能相邻,问是否可能用1-4这四种颜色对矩形染色,使得相邻的矩形颜色不同,如果可以输出YES,并输出染色方案。
题解:
根据四色定理,染色一定会成功。
因为边长为奇数
(1)我们只看左下角坐标,如果两个数值都为奇数,那么右上角坐标一定两个都为偶数,所以所有左下标坐标为奇数的不会相交,可赋值为1。
(2)
如果x轴为偶数,可能与1的情况左右相邻赋值为2。
(3)
如果y轴为偶数,可能与1的情况左右相邻,赋值为3。
(4)
其余赋值为4。
换句话说,根据右下角的点x,y坐标点奇偶性,可以把矩形分为4类,这四类类之间是不会相邻的。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const int inf=0x3fffffff;
const ll mod=1000000007;
const int maxn=20+10;
int main()
{
int n;
scanf("%d",&n);
puts("YES");
rep(i,1,n+1)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1&1)
{
if(y1&1) puts("1");
else puts("2");
}
else
{
if(y1&1) puts("3");
else puts("4");
}
}
return 0;
}