Codeforces Round #395 (Div. 2) D. Timofey and rectangles

本文探讨了一个具体的编程问题:如何利用四色定理为一系列互不相交且边长为奇数的矩形进行染色,确保相邻矩形颜色不同。通过分析矩形坐标的特点,提出了一个简洁高效的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
当时c没思路,简单的看了一下d,四色原理。。。。并且没注意那个边肯定是奇数的条件。。。。。。。然后不会。。就去怼c了,一直也没回来看d

其实不难。。因为边长肯定是奇数,所以只有左下点坐标全奇,全偶或一奇一偶这四种情况互相之间才有可能有边相邻

全奇和全偶之间就不说了,

全奇和一奇一偶,举个例子

x偶y奇

1 1 4 4 

4 1 3 2 

x奇y偶

1 1 4 4

1 4 2 5

全偶和一奇一偶

x偶y奇

0 0 3 3 

0 3 1 4

x奇y偶

0 0 3 3

3 0 4 1

#include<stdio.h>
#include<math.h>
int x[500005],y[500005];
int main()
{
	int n,i,a,b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d %d %d %d",&x[i],&y[i],&a,&b);
	printf("YES\n");
	for(i=0;i<n;i++)
	{
		if(x[i]&1&&y[i]&1)
		printf("1\n");
		else if(x[i]&1&&!(y[i]&1))
		printf("2\n");
		else if(!(x[i]&1)&&y[i]&1)
		printf("3\n");
		else 
		printf("4\n");
	}
	return 0;
}

这次做的很差,光怼c还没怼出来,d也直接弃了,

看题一定要看清题意!!!不要遗漏!!!

无论什么题,都要思考至少五分钟在决定是否跳过!!

好好学英语。。。。。。。。。。。。。。。。。。。。。。。。。。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值