cf547D. Mike and Fish(歐拉迴路)

來源:互聯網
上載者:User

標籤:problem   lower   tchar   mod   歐拉   unique   ++   getc   str   

題意

題目連結

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(歐拉迴路)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.