CF#764 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

题意:在一个平面直角坐标系中给出n个矩形不相邻的两端点x1,y1,x2,y2(矩形互不重叠且边长一定为奇数),我们要将所有矩形染色,且任意两个相互接触的矩形不能为同一颜色,问我们能否用4种颜色对所有的n个矩形完成染色, 如果能,输出任意一满足条件的情况即可
思路:没啥好说的。。就是四色定理的运用。

四色定理:
                                            
                    

我们先用四种颜色涂上空间坐标系的每一个点,并任意选取一个边长为奇数的矩形,此时我们惊奇的发现w(゚Д゚)w矩形的四个端点都为同一种颜色,并且这个矩形一周并没有与顶点颜色相同的颜色!这题我们就是运用了这个性质。
#include <bits/stdc++.h>
using namespace std;

int n;

int main(){
    while(scanf("%d", &n) == 1){
        printf("YES\n");
        for(int i = 0; i < n; i++){
            int x1, y1, x2, y2;
            scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
            if(x2&1){
                printf(y2&1 ? "3\n" : "1\n");
            }
            else{
                printf(y2&1 ? "4\n" : "2\n");
            }
        }
    }
}





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值