cf547D. Mike and Fish(歐拉回路)
阿新 • • 發佈:2018-10-24
i++ ble namespace vector 數據 pac etc tor code
題意
題目鏈接
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(歐拉回路)