UVALive 6663 Count the Regions 離散+bfs染色_(:зゝ∠)_,uvalive6663

來源:互聯網
上載者:User

UVALive 6663 Count the Regions 離散+bfs染色_(:зゝ∠)_,uvalive6663

題目連結:點擊開啟連結

gg。。==

#include <cstdio>#include <cstring>#include<iostream>#include <queue>#include <set>#include <map>#include <algorithm>#include <string>using namespace std;#define ll long long#define inf 10000000#define N 55typedef pair<int,int> pii;struct node{    int lx, ly, rx, ry;    void put(){printf("    (%d,%d) - (%d,%d) ",lx,ly,rx,ry);}}a[N];vector<int>X,Y;ll mp[200][200];int vis[200][200];int step[4][2] = {-1,0, 0,-1, 0,1,  1,0};int n;void bfs(int x, int y){    queue<int>qx, qy;    qx.push(x); qy.push(y);    vis[x][y]=1;    while(!qx.empty()) {        int ux = qx.front(); qx.pop();        int uy = qy.front(); qy.pop();        for(int i = 0; i < 4; i++)        {            int vx = step[i][0] + ux, vy = step[i][1] + uy;            if(vx<0 || vx>=200 || vy<0 || vy>=200)continue;            if(vis[vx][vy])continue;            if(mp[ux][uy]!=mp[vx][vy])continue;            vis[vx][vy] = 1;            qx.push(vx); qy.push(vy);        }    }}void input(){    X.clear(); Y.clear();    for(int i = 1; i <= n; i++)    {        scanf("%d %d %d %d",&a[i].lx,&a[i].ly,&a[i].rx,&a[i].ry);        X.push_back(a[i].lx);        Y.push_back(a[i].ly);        X.push_back(a[i].rx);        Y.push_back(a[i].ry);    }    sort(X.begin(), X.end());    X.erase(unique(X.begin(), X.end()), X.end());    sort(Y.begin(), Y.end());    Y.erase(unique(Y.begin(), Y.end()), Y.end());    for(int i = 1; i <= n; i++){        a[i].lx = lower_bound(X.begin(), X.end(), a[i].lx) - X.begin()+10;        a[i].rx = lower_bound(X.begin(), X.end(), a[i].rx) - X.begin()+10;        a[i].ly = lower_bound(Y.begin(), Y.end(), a[i].ly) - Y.begin()+10;        a[i].ry = lower_bound(Y.begin(), Y.end(), a[i].ry) - Y.begin()+10;    }/**/}int main(){     int i, j;    while(scanf("%d",&n), n){        input();        memset(mp, 0, sizeof mp);        memset(vis, 0, sizeof vis);        for(i = 1; i <= n; i++)            for(j = a[i].lx; j < a[i].rx; j++)                for(int k = a[i].ry; k< a[i].ly; k++)                    mp[j][k] = mp[j][k] | (1ll<<i);        int ans = 0;        for(i = 0; i < 200; i++)            for(j = 0; j < 200; j++)                if(!vis[i][j])                {                    ans++;                    bfs(i,j);                }        cout<<ans<<endl;    }    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.