CF763Bティモフィーと長方形の問題の解決策

CF763Bティモフィーと長方形

質問の意味:与えられたn(n≤5e5)n(n≤5e5)n n5 e 5 長方形の対角頂点。これらの長方形は互いに素であり、辺の長さが奇数であることが保証されています。隣接する長方形の色が異なるように、これらの長方形を4色で着色する必要があります。可能かどうかを尋ねます。可能な場合は、オプションのいずれかを出力します。

解決策:質問には3つの重要な情報があります。互いに素な長方形、4つの色、および辺の長さが奇数です。
互いに素な長方形は、行列が1つの辺に隣接しているか、互いに離れていることを意味します。
四色定理を通して、答えは可能でなければなりません。
ここに画像の説明を挿入します
それで、これを考えて、計画を出力したい場合、nが大きすぎて暴力を使用できず、使用されていない別の条件がある場合、長方形の長さは奇数であることが保証されますか?この条件の用途は何ですか?絵を描きます。
ここに画像の説明を挿入します
この長方形を表すために左上の点のみを使用する場合、隣接する長方形はパリティの区別で4つのタイプで表すことができ、正確には4つの色に対応するため、水平方向を判断するだけで済みます。入力時の長方形の垂直左上隅。座標は問題ありません。

コード

#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