题目链接:

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. 05.使用jdk发布webservice服务

    无论服务端是用什么写的,使用框架写的还是用jdk写的,它都会发布出来这样一个东西.主要你遵循咱们这七个步骤来走就可以调用了. 咱们现在转换一下角色,自己发布一个服务让别人去调.怎么来发布一个服务? 我 ...

  2. Nginx调优实战

    Nginx配置文件性能微调 全局的配置 user www-data; pid /var/run/nginx.pid; worker_processes auto; worker_rlimit_nofi ...

  3. Gym-101915A Printing Books 模拟

    题面 题意:给你N,X,   X表示这本书从X开始编号,每个X是几位数,计数器就加几, 然后问你如果从X,开始编号,计数器为N的时候,翻了几页,不能刚好为N输出-1. (例如,5 99,答案为2,因为 ...

  4. firewalld使用

    1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status f ...

  5. linq的教程

    http://www.cnblogs.com/lifepoem/archive/2011/12/16/2288017.html

  6. Ssh safe

    新建用户,设置密码 useradd eason passwd eason 不允许root直接登陆 修改配置文件 vi /etc/ssh/sshd_config 禁止root登录 查找“#PermitR ...

  7. 机器学习PAI为你自动写歌词,妈妈再也不用担心我的freestyle了(提供数据、代码)

    背景 最近互联网上出现一个热词就是“freestyle”,源于一个比拼rap的综艺节目.在节目中需要大量考验选手的freestyle能力,freestyle指的是rapper即兴的根据一段主题讲一串r ...

  8. Verilog之openMSP430(1)

    openMSP430_IO interrupt Verilog file: omsp_gpio.v //================================================ ...

  9. 读书笔记「Python编程:从入门到实践」_3.列表简介

    3.1 列表是什么 列表 由一系列按特定顺序排列的元素组成. 在Python中,用方括号([] )来表示列表,并用逗号来分隔其中的元素. 3.1.1 访问列表元素 指出列表的名称,再指出元素的索引   ...

  10. promise待看文档备份

    http://swift.gg/2017/03/27/promises-in-swift/ http://www.cnblogs.com/feng9exe/p/9043715.html https:/ ...