标签:http os io for ar line amp size
题目链接:点击打开链接
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 55 typedef 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; }
UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_,布布扣,bubuko.com
UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_
标签:http os io for ar line amp size
原文地址:http://blog.csdn.net/qq574857122/article/details/38462829