UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_
题目链接: 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染色_(:зゝ∠)_的更多相关文章
- UVALive 6663 Count the Regions --离散化+DFS染色
题意:给你n(n<=50)个矩形(左上角坐标和右下角坐标),问这些矩形总共将平面分成多少个部分.坐标值可能有1e9. 分析:看到n和坐标的范围,容易想到离散化,当时就没想到离散化以后怎么判断区域 ...
- UvaLive 6663 Count the Regions 离散化+DFS
链接:http://vjudge.net/problem/viewProblem.action?id=49408 题意:在平面内给出若干个矩形,求出它们能将整个平面分成多少份. 思路:刚開始一眼看到认 ...
- [UVALive 6663 Count the Regions] (dfs + 离散化)
链接:https://icpcarchive.ecs.baylor.edu/index.php? option=com_onlinejudge&Itemid=8&page=show_p ...
- UVALive 3977 BFS染色
这个题意搞了半天才搞明白 就是如果定义一个d-summit,即从该点到另一个更高的点,经过的路径必定是比当前点低至少d高度的,如果该点是最高点,没有比他更高的,就直接视为顶点 其实就是个BFS染色,先 ...
- HDU 2444 二分图判断 (BFS染色)+【匈牙利】
<题目链接> 题目大意: 有N个人,M组互相认识关系互相认识的两人分别为a,b,将所有人划分为两组,使同一组内任何两人互不认识,之后将两个组中互相认识的人安排在一个房间,如果出现单人的情况 ...
- 训练指南 UVALive - 3523 (双联通分量 + 二分图染色)
layout: post title: 训练指南 UVALive - 3523 (双联通分量 + 二分图染色) author: "luowentaoaa" catalog: tru ...
- 【Luogu】P1330封锁阳光大学(bfs染色)
题目链接 这题恶心死我了. bfs染色,统计每个联通块两色的个数,ans加它们的最小值. #include<cstdio> #include<cctype> #include& ...
- XMU 1617 刘备闯三国之汉中之战 【BFS+染色】
1617: 刘备闯三国之汉中之战 Time Limit: 1000 MS Memory Limit: 128 MBSubmit: 6 Solved: 5[Submit][Status][Web B ...
- UVALive - 3977 Summits (BFS染色)
题目大意:坑爹的题目.题意那么难理解. 讲的就是,假设该点是山顶的话(高度为h).那么以该点为中心,往外辐射.走高度大于h-d的点,到达不了还有一个比它高的点 这就提示了,高度要从大到小排序,依次以高 ...
随机推荐
- Java访问HTTPS时证书验证问题
为了尽可能避免安全问题,公司的很多系统服务都逐步https化,虽然开始过程会遇到各种问题,但趋势不改.最完美的https应用是能实现双向认证,客户端用私钥签名用服务端公钥加密,服务端用私钥签名客户端都 ...
- postgresql 常规操作以及检查备份
一.建表时,复制源表的信息test=# test=# \d test.t1 Table "test.t1" Column | Type | Collation | Nullable ...
- POJ 3275 Floyd传递闭包
题意:Farmer John想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛(1 ≤ N ≤ 1,000).FJ通过比较,已经知道了M(1 ≤ M ≤ 10,000)对相对关系.每一对关系表示为&q ...
- JavaScrip——插入地图
具体操作步骤:1.百度搜索:百度地图生成器 2.打开第一个,复制网址http://api.map.baidu.com/lbsapi/creatmap/index.html,打开3.页面显示为 4.根据 ...
- 控件——DataGridview
控件:DataGridview 用来显示数据, 可以显示和编辑来自多种不同类型的数据源的表格数据. 一.两种显示数据的方式:手动,后台代码 主要通过后台代码:先建立三大类 然后绑定 ...
- Android拼图-变形金刚
开篇 学了几个月的Android开发,动手做了一个简单的拼图小游戏,没有使用游戏框架,名字也纯属娱乐,比较粗糙请大家一笑别骂. 游戏界面是一张图片切割的6*6的小图片,并将其中一块拿走,玩家通过不同的 ...
- 在maven项目结构下对于Resources目录下文件的存取
在maven项目中,文件结构如下: proj ---src ----main ----java ----Main.java ----resources ----userFile.properties ...
- HTML 单击a标签 实现下载文件而不是浏览器打开预览
<a d ownload class="down" title="">
- 如何在vue里面正确的引用 jquery 和 第三方插件
vue-cli webpack全局引入jquery(jq通过npm安装的并非本地文件) 1.首先在package.json里加入, dependencies:{ "jquery" ...
- 素数(Prime)
素数的判断: #include<math.h> bool IsPrime(int n) { ) return false; int sqr = (int)sqrt(1.0*n); ; i& ...