题目链接:

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. 杂项:hive(数据仓库工具)

    ylbtech-杂项:hive(数据仓库工具) hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的sql查询功能,可以将sql语句转换为MapRedu ...

  2. Python环境设置-zlib not available

    今天在Linux中安Python3的时候,出现了一个错误:zipimport.ZipImportError: can‘t decompress data; zlib not available 网上找 ...

  3. [Offer收割]编程练习赛41

    比赛日程安排 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #incl ...

  4. 使用Axis2方式发布webService实例说明

    1.简单的pojo方式: 不需要写配置文件,直接把class文件拷贝到axis2的WEB-INF目录下的poji文件夹下即可.但其局限性表现在,实现类不能有包声明,这在实际开发过程中使用较少,这里不做 ...

  5. WCF - NetCtP 双工错误列表

    1. 在服务 Transfer 实现的协定列表中找不到协定名称 "IMetadataExchange" 将 ServiceMetadataBehavior 添加到配置文件或直接添加 ...

  6. Eigen库对齐问题:declspec(align('16')) 的形参将不被对齐

    一:错误提示:error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned 英文提示:erro ...

  7. 04-手把手教你把Vim改装成一个IDE编程环境(图文)

    Linux下编程一直被诟病的一点是: 没有一个好用的IDE, 但是听说Linux牛人, 黑客之类的也都不用IDE. 但是对我等从Windows平台转移过来的Coder来说, 一个好用的IDE是何等的重 ...

  8. 04--奠定MYSQL江湖地位的开发注意要点

    为不同的行业提供不同的MYSQL应用场景 吴炳锡老师谈到,不同行业的业务有不同的特点,选择好一个适合自己行业的MYSQL应用场景至关重要. 互联网行业 速度一直都是互联网发展的第一要义,互联网行业所使 ...

  9. 03--(二)编程实践中C语言的一些常见细节

    编程实践中C语言的一些常见细节(转载) 对于C语言,不同的编译器采用了不同的实现,并且在不同平台上表现也不同.脱离具体环境探讨C的细节行为是没有意义的,以下是我所使用的环境,大部分内容都经过测试,且所 ...

  10. logging模块、shutil模块、subprocess模块、xml模块

    logging模块 shutil模块 subprocess模块 xml模块 logging模块 函数式简单配置 import logging logging.debug('debug message' ...