CF763B Timofey and rectangles题解

CF763B Timofey and rectangles

题意:给定 n ( n ≤ 5 e 5 ) n(n≤5e5) n(n5e5)个矩形的对角顶点,这些矩形保证不相交且边长长度是奇数,要问用四种颜色给这些矩形染色,使得他们相邻的矩形的颜色各不相同,问是否有可能,如果有可能,输出任意一种方案。

解法:题中给出了三个很重要的信息:不相交矩形,四种颜色,边长长度是奇数。
不相交矩形意味着矩阵要么共一条边的相邻,要么相离。
四种颜色,通过四色定理可知,答案一定是有可能的。
在这里插入图片描述
那么如果想到了这里,要输出方案的话,n太大导致不能用暴力,还有一个条件没有用到,矩形的边长保证长度是奇数?这个条件有什么用?我们画一个图。
在这里插入图片描述
会发现若只用左上角的点代表这个矩形的话,相邻的矩形在奇偶区分上分别能用四种表示,那么正好,就对应四种颜色,因此只需要在输入时判断矩形左上角横纵坐标就可。

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-4
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
    
    
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') {
    
     if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') {
    
     res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {
    
    1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const LL INF = 1e18;
const int N = 5e5+10;
const LL Mod = 1e9+7;
const int M = 110;
int main() {
    
    
  int n, a, b, c, d;
  scanf("%d", &n);
  int ma, mb;
  puts("YES");
  while(n--) {
    
    
    scanf("%d%d%d%d", &a, &b, &c, &d);
    ma = min(a, c); mb = min(b, d);
    ma = abs(ma); mb = abs(mb);
    if(ma % 2 == 0 && mb % 2 == 0) puts("1");
    else if(ma % 2 == 0 && mb % 2 == 1) puts("2");
    else if(ma % 2 == 1 && mb % 2 == 0) puts("3");
    else puts("4");
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43408978/article/details/108956487