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 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个边长为奇数的矩形的坐标,问用四种颜色是否能完成染色,并给出一种染色方案。
题解:根据四色定理知道,四种颜色一定能完成染色。
主要是odd入手,对于一个坐标(x,y),有
x%2==0&&y%2==0
x%2==1&&y%2==0
x%2==0&&y%2==1
x%2==1&&y%2==0
任意相邻的两个矩形,因为odd最后对2取余的结果就是不同的
代码如下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
int x1[maxn],x2[maxn],y1[maxn],y2[maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;++i)
scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
puts("YES");
for(int i=0;i<n;++i)
{
int x=abs(min(x1[i],x2[i]));
int y=abs(min(y1[i],y2[i]));
if(x%2==1 && y%2==1)
puts("1");
else if(x%2==1 && y%2==0)
puts("2");
else if(x%2==0 && y%2==1)
puts("3");
else if(x%2==0 && y%2==0)
puts("4");
}
}
return 0;
}
然后膜一发dls:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
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 mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head
int n,x,y;
int main() {
scanf("%d",&n);
puts("YES");
rep(i,0,n) {
scanf("%d%d%*d%*d",&x,&y);
printf("%d\n",2*(x&1)+(y&1)+1);
}
}