题目链接:

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. 对象设计解耦的方法IOC和DI

    耦合关系不仅会出现在对象与对象之间,也会出现在软件系统的各模块之间,以及软件系统和硬件系统之间.如何降低系统之间.模块之间和对象之间的耦合度,是软件工程永远追求的目标之一.为了解决对象之间的耦合度过高 ...

  2. golang二维码

    package main import ( "github.com/boombuler/barcode" "github.com/boombuler/barcode/qr ...

  3. laydate.js时间选择

    例子: <asp:HiddenField ID="hfdDateBuid3" runat="server" /> <script type=& ...

  4. html+css布局整理笔记

    基本概念 布局模型 流动模型(Flow) 浮动模型(Float) 层模型(Layer) 流动模型 默认的网页布局模式,流动布局模型有两个比较典型的特征: 第一,块级元素都会在所处的包含元素内自上而下按 ...

  5. 如何使用fetch

    Fetch API  提供了一个 JavaScript接口,用于访问和操纵HTTP管道的部分,例如请求和响应.它还提供了一个全局fetch()方法,该方法提供了一种简单,合乎逻辑的方式来跨网络异步获取 ...

  6. WordPress的wordfence插件的设置方法

  7. CUDA与OpenCL架构

    CUDA与OpenCL架构 目录 CUDA与OpenCL架构 目录 1 GPU的体系结构 1.1 GPU简介 1.2 GPU与CPU的差异 2 CUDA架构 2.1 硬件架构 2.1.1 GPU困境 ...

  8. JS 实现类似打印的效果(一个字一个字显示)

    <pre id="aa"></pre> <div style="display:none" id="w"> ...

  9. 01--数据结构——动态链表(C++)

    数据结构——动态链表(C++)   定义一个节点: [cpp] view plain copy   print? #include <iostream> using namespace s ...

  10. 洛谷P3165 [CQOI2014]排序机械臂 Splay维护区间最小值

    可以将高度定义为小数,这样就完美的解决了优先级的问题. Code: #include<cstdio> #include<algorithm> #include<cstri ...