UVALive 6663 Count the Regions discretization + bfs dyeing _ (: Invalid partition) _, uvalive6663

Source: Internet
Author: User

UVALive 6663 Count the Regions discretization + bfs dyeing _ (: Invalid partition) _, uvalive6663

Question link: Click the open link

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;}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.