【坐标离散化】AOJ0531- Paint Color

日文题……一开始被题目骗了以为真的要写文件?
题目大意&&解答戳:❀
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int w,h,n,ans;
const int MAXN=+;
int x1[MAXN],x2[MAXN],y1[MAXN],y2[MAXN];
int hashx[MAXN*],hashy[MAXN*];
int fld[MAXN*][MAXN*];
int dx[]={,,,-};
int dy[]={,-,,}; void compress()
{
int tx=,ty=;
for (int i=;i<=n;i++)
{
hashx[++tx]=x1[i];hashx[++tx]=x2[i];
hashy[++ty]=y1[i];hashy[++ty]=y2[i];
}
hashx[++tx]=;hashx[++tx]=w;
hashy[++ty]=;hashy[++ty]=h;
sort(hashx+,hashx+tx+);
sort(hashy+,hashy+ty+);
w=unique(hashx+,hashx+tx+)-(hashx+);
h=unique(hashy+,hashy+ty+)-(hashy+);
for (int i=;i<=n;i++)
{
x1[i]=lower_bound(hashx+,hashx+w+,x1[i])-hashx-;
x2[i]=lower_bound(hashx+,hashx+w+,x2[i])-hashx-;
y1[i]=lower_bound(hashy+,hashy+h+,y1[i])-hashy-;
y2[i]=lower_bound(hashy+,hashy+h+,y2[i])-hashy-;
}
w--;h--;
} void init()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
compress();
} void imos() /*imos?*/
{
memset(fld,,sizeof(fld));
for (int i=;i<=n;i++)
{
fld[x1[i]][y1[i]]++;
fld[x2[i]][y2[i]]++;
fld[x1[i]][y2[i]]--;
fld[x2[i]][y1[i]]--;
} for (int i=;i<w;i++)
for (int j=;j<h;j++)
fld[i][j]+=fld[i][j-]; for (int j=;j<h;j++)
for (int i=;i<w;i++)
fld[i][j]+=fld[i-][j];
} void bfs(int x,int y)
{
ans++;
queue<int> qx,qy;
qx.push(x);
qy.push(y);
fld[x][y]=;
while (!qx.empty())
{
int xx=qx.front();qx.pop();
int yy=qy.front();qy.pop();
for (int i=;i<;i++)
{
int nx=xx+dx[i],ny=yy+dy[i];
if (nx< || ny< || nx>w || ny>h || fld[nx][ny]>) continue;
qx.push(nx);
qy.push(ny);
fld[nx][ny]=;
}
}
} void solve()
{
ans=;
for (int i=;i<w;i++)
for (int j=;j<h;j++)
if (fld[i][j]==) bfs(i,j);
printf("%d\n",ans);
} int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
while (~scanf("%d%d",&w,&h)&&w&&h)
{
init();
imos();
solve();
}
return ;
}
【坐标离散化】AOJ0531- Paint Color的更多相关文章
- Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)
传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...
- Greedy:Paint Color(AOJ 0531)
涂颜料 题目大意:在一个1000000*1000000的矩阵中放入几块木板,问你这些木板把矩阵划分成了几个区域?输入会给左下角和右上角的坐标,输入W==0且H==0结束. 这一题是书上的作业题,书上有 ...
- AOJ 0531 坐标离散化
涂色:(日文题目,自己翻译成了中文)为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌.三合板上不需要涂色的部分预先贴好了护板.被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编 ...
- Aizu - 0531 Paint Color
白书例题,直接用书上的暴力压缩坐标是可以的,但是看了别人的博客的写法,大概是理解了思想但是看不懂为什么那么压缩,先放这,等明白了补上 #define debug #include<stdio.h ...
- hihoCoder#1079(线段树+坐标离散化)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在回国之后,重新过起了朝7晚5的学生生活,当然了,他们还是在一直学习着各种算法~ 这天小Hi和小Ho所在的学 ...
- AOJ 0531:Paint Color(二维离散+imos)
[题目链接] http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0531 [题目大意] 给出一张图,和一些矩形障碍物,求该图没被障碍物覆 ...
- nyoj_600:花儿朵朵(树状数组+坐标离散化)
http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...
- Atlantis(坐标离散化)
http://poj.org/problem?id=1151 题意:给出矩形的左上角坐标和右下角坐标(坐标的y轴是向下的),求出矩形面积的并.. 今天好困啊..迷迷糊糊的听会神给讲了讲,敲完之后调试了 ...
- nyoj 600:花儿朵朵(树状数组+坐标离散化)
http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...
随机推荐
- 论文中“but”与“however”的区别
- ubuntu 下没有pthread库以及报undefined reference to 'pthread_create'的解决方法
https://blog.csdn.net/dyzhen/article/details/79058554
- MySQL索引背后的数据结构及算法原理 (转)
摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BT ...
- MySQL忘记密码了怎么办?
接手一个项目时,如果上一位负责人没有把项目文档.账号密码整理好是一件很头疼的事情.. 例如,当你想打开MySQL数据库的时候 输入: mysql -u root -p 一回车想输入密码,发现密码错误! ...
- [BZOJ 1260][CQOI2007]涂色paint 题解(区间DP)
[BZOJ 1260][CQOI2007]涂色paint Description 假设你有一条长度为5的木版,初始时没有涂过任何颜色.你希望把它的5个单位长度分别涂上红.绿.蓝.绿.红色,用一个长度为 ...
- MacOS 下提示APP 损坏 无法安装 解决方法
sudo spctl --master-disable
- Dream_Spark定制第二课
Spark版本定制第2天:通过案例对SparkStreaming透彻理解之二 本期内容: 1 解密Spark Streaming运行机制 2 解密Spark Streaming架构 一切不能进行实时流 ...
- centos6.8安装mysql5.6【转】
首先先要去看看本机有没有默认的mysql, 本地默认有的,我们应先卸载,在安装新的这个逻辑. rpm -qa | grep mysql 我本机默认安装的mysql5.1.73 下一步删除 rpm -e ...
- H2内嵌数据库使用步骤
1.找到h2数据库的jar包 D:\repositories\com\h2database\h2\1.4.187\h2-1.4.187.jar 2.双击jar包,配置连接信息 Driver Class ...
- Project Euler Problem4
Largest palindrome product Problem 4 A palindromic number reads the same both ways. The largest pali ...