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

题目链接:http://codeforces.com/contest/764/problem/D


题目的意思是说用四种颜色给矩形上色,要求相邻的矩形不能为同一种颜色,每个矩形的边长为奇数。


这个题我想麻烦了,想到了IOI99年发的Picture的那篇论文了,想着先标号,用扫面线什么的,后来去翻了翻那篇论文,题目果然不一样。


我就不讲解了,我也没做出来,放上大牛的链接:http://blog.csdn.net/qq_34374664/article/details/54850964


代码:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct node{
    int x1,x2;
    int y1,y2;
}xin[700000];
int main(){
    int n;
    while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
            scanf("%d%d",&xin[i].x1,&xin[i].y1);
            scanf("%*d%*d");
        }
        cout<<"YES"<<endl;
        for(int i=0;i<n;i++){
            int x=xin[i].x1;
            int y=xin[i].y1;
            if(!(x&1)&&!(y&1)){
                printf("1\n");
            }
            else if(!(x&1)&&(y&1)){
                printf("2\n");
            }
            else if((x&1)&&!(y&1)){
                printf("3\n");
            }
            else{
                printf("4\n");
            }
        }
    }
    return 0;
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值