Codeforces 763B 想法

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个矩形的左上角和右下角坐标,问用4种颜色给所有矩形染色,相邻的矩形颜色不能相同,怎么染。边长是奇数。


题解:

可以把矩形的左下角左边分为  奇奇  奇偶  偶奇  偶偶

1+row%2*2+col%2 即是答案

下面证明一下这个公式

假设另一个矩形与当前矩形相邻,是纵向相邻

那么这个矩形坐标可写为(row-k,col-odd)

如果同颜色  那么就是

1+row%2*2+col%2=1+(row-k)%2*2+(col-odd)%2

假设col-odd是奇数

row%2*2=(row-k)%2*2+1

左面是偶数,右面是偶数+1  矛盾

假设col-odd是偶数

row%2*2+1=(row-k)%2*2  矛盾

假设横向相邻

1+row%2*2+col%2=1+(row-odd)%2*2+(col-k)%2

假设row-odd是奇数

col%2=2+(col-k)%2

很明显也是矛盾的

偶数同理

所以答案成立


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int n,i;
	scanf("%d",&n);
	printf("YES\n");
	int a,b,c,d;
	for(i=1;i<=n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",2*(abs(a)%2)+abs(b)%2);
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值