cf547D. Mike and Fish(欧拉回路)

Posted zwfymqz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf547D. Mike and Fish(欧拉回路)相关的知识,希望对你有一定的参考价值。

题意

题目链接

Sol

说实话这题我到现在都不知道咋A的。

考试的时候是对任意相邻点之间连边,然后一分没有

然后改成每两个之间连一条边就A了。。

按说是可以过掉任意坐标上的点都是偶数的数据啊。。

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second 
using namespace std;
const int MAXN = 2e5 + 10, INF = 1e9 + 10, mod = 998244353;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int x[MAXN], y[MAXN], date[MAXN], numx[MAXN], numy[MAXN];
vector<int> E[MAXN];
vector<Pair> tmp[MAXN];
void Get(int *a) {
    for(int i = 1; i <= N; i++) date[i] = a[i];
    sort(date + 1, date + N + 1);
    int num = unique(date + 1, date + N + 1) - date - 1;
    for(int i = 0; i <= num; i++) tmp[i].clear();
    for(int i = 1; i <= N; i++) a[i] = lower_bound(date + 1, date + num + 1, a[i]) - date - 1, tmp[a[i]].push_back(MP(a[i], i));
    for(int i = 0; i <= num; i++) {
        if(tmp[i].size() < 2) continue;
        sort(tmp[i].begin(), tmp[i].end());
        for(int j = 0; j < tmp[i].size() - 1; j += 2) {
            int x = tmp[i][j].se, y = tmp[i][j + 1].se;
            E[x].push_back(y);
            E[y].push_back(x);
        }
    }
}
int vis[MAXN], vis2[MAXN];
void BFS(int k) {
    queue<int> q;
    vis[k] = 1; q.push(k); 
    while(!q.empty()) {
        int p = q.front(); q.pop(); 
        if(vis2[p]) continue; vis2[p] = 1;
        for(int i = 0; i < E[p].size(); i++) {
            int to = E[p][i];
            vis[to] = vis[p] ^ 1;
            q.push(to);
        }
    }
    
}
int main() {
    N = read();
    for(int i = 1; i <= N; i++) x[i] = read(), y[i] = read();
    Get(x); Get(y);
    for(int i = 1; i <= N; i++) if(!vis2[i]) BFS(i);
    for(int i = 1; i <= N; i++) putchar(vis[i] == 0 ? 'b' : 'r');
    return 0;
}

以上是关于cf547D. Mike and Fish(欧拉回路)的主要内容,如果未能解决你的问题,请参考以下文章

CF547D Mike and Fish 建图

CF 547E Mike and Friends

CF547E Mike and Friends

codeforces #305 D Mike and Fish

CF798C Mike and gcd problem

Codeforces 547B Mike and Feet(单调栈)