题目链接:

option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接

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染色_(:зゝ∠)_的更多相关文章

  1. UVALive 6663 Count the Regions --离散化+DFS染色

    题意:给你n(n<=50)个矩形(左上角坐标和右下角坐标),问这些矩形总共将平面分成多少个部分.坐标值可能有1e9. 分析:看到n和坐标的范围,容易想到离散化,当时就没想到离散化以后怎么判断区域 ...

  2. UvaLive 6663 Count the Regions 离散化+DFS

    链接:http://vjudge.net/problem/viewProblem.action?id=49408 题意:在平面内给出若干个矩形,求出它们能将整个平面分成多少份. 思路:刚開始一眼看到认 ...

  3. [UVALive 6663 Count the Regions] (dfs + 离散化)

    链接:https://icpcarchive.ecs.baylor.edu/index.php? option=com_onlinejudge&Itemid=8&page=show_p ...

  4. UVALive 3977 BFS染色

    这个题意搞了半天才搞明白 就是如果定义一个d-summit,即从该点到另一个更高的点,经过的路径必定是比当前点低至少d高度的,如果该点是最高点,没有比他更高的,就直接视为顶点 其实就是个BFS染色,先 ...

  5. HDU 2444 二分图判断 (BFS染色)+【匈牙利】

    <题目链接> 题目大意: 有N个人,M组互相认识关系互相认识的两人分别为a,b,将所有人划分为两组,使同一组内任何两人互不认识,之后将两个组中互相认识的人安排在一个房间,如果出现单人的情况 ...

  6. 训练指南 UVALive - 3523 (双联通分量 + 二分图染色)

    layout: post title: 训练指南 UVALive - 3523 (双联通分量 + 二分图染色) author: "luowentaoaa" catalog: tru ...

  7. 【Luogu】P1330封锁阳光大学(bfs染色)

    题目链接 这题恶心死我了. bfs染色,统计每个联通块两色的个数,ans加它们的最小值. #include<cstdio> #include<cctype> #include& ...

  8. XMU 1617 刘备闯三国之汉中之战 【BFS+染色】

    1617: 刘备闯三国之汉中之战 Time Limit: 1000 MS  Memory Limit: 128 MBSubmit: 6  Solved: 5[Submit][Status][Web B ...

  9. UVALive - 3977 Summits (BFS染色)

    题目大意:坑爹的题目.题意那么难理解. 讲的就是,假设该点是山顶的话(高度为h).那么以该点为中心,往外辐射.走高度大于h-d的点,到达不了还有一个比它高的点 这就提示了,高度要从大到小排序,依次以高 ...

随机推荐

  1. 22.Generate Parentheses[M]括号生成

    题目 Given n pairs of parentheses, write a function to generate all combinations of well-formed parent ...

  2. 多线程之HttpClient

    在程序用调用 Http 接口.请求 http 资源.编写 http 爬虫等的时候都需要在程序集中进行 Http 请求. 很多人习惯的 WebClient.HttpWebRequest 在 TPL 下很 ...

  3. 关于中文期刊LaTeX的CCT相关

    最近写完了大论文,回身看了一下CTeX的信息,看了下弄改进版套装的山大和清华的两位大神的博客,发现大神们倒腾过CCT. CCT的FTP还是一直可用的,ftp://ftp.cc.ac.cn/pub/cc ...

  4. 09.javaweb简单标签编程

    一.简单标签 1,  简介:由于传统标签使用三个标签接口来完成不同的功能,显得过于繁琐,不利于标签技术的推广, SUN公司为降低标签技术的学习难度,在JSP 2.0中定义了一个更为简单.便于编写和调用 ...

  5. Android AlertDialog 动态更新里面的ListView数据

    1:和ListView的数据跟新是基本一样的. 2:Activity代码示例 public class MainActivity extends AppCompatActivity { AlertDi ...

  6. SQL Server-聚焦过滤索引提高查询性能

    前言 这一节我们还是继续讲讲索引知识,前面我们讲了聚集索引.非聚集索引以及覆盖索引等,在这其中还有一个过滤索引,通过索引过滤我们也能提高查询性能,简短的内容,深入的理解,Always to revie ...

  7. Mac使用ssh登录远程linux系统查看jetty日志及同时使用github工具

    转载请注明出处:http://www.houxiurong.com/?post=27 Mac默认是安装了ssh工具软件的. 先用mac的 终端工具生成 id_rsa 和id_rsa.pub 秘钥,生成 ...

  8. angular 常用写法

    1.ng-repeat 数组数据中,不允许数组中有相同的两个数据,这个时候用下标去管理数据便可以解决这个问题 ng-repeat="item in list track by $index& ...

  9. JS 蓝球弹起的高度 100 米 第几次高度小于1米

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. input type=”file“ change事件只执行一次的问题

    js解决办法 HTML:<input id="file",type="file" onchange="upload()" /> ...