日文题……一开始被题目骗了以为真的要写文件?

题目大意&&解答戳:

 #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的更多相关文章

  1. Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)

    传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...

  2. Greedy:Paint Color(AOJ 0531)

    涂颜料 题目大意:在一个1000000*1000000的矩阵中放入几块木板,问你这些木板把矩阵划分成了几个区域?输入会给左下角和右上角的坐标,输入W==0且H==0结束. 这一题是书上的作业题,书上有 ...

  3. AOJ 0531 坐标离散化

    涂色:(日文题目,自己翻译成了中文)为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌.三合板上不需要涂色的部分预先贴好了护板.被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编 ...

  4. Aizu - 0531 Paint Color

    白书例题,直接用书上的暴力压缩坐标是可以的,但是看了别人的博客的写法,大概是理解了思想但是看不懂为什么那么压缩,先放这,等明白了补上 #define debug #include<stdio.h ...

  5. hihoCoder#1079(线段树+坐标离散化)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在回国之后,重新过起了朝7晚5的学生生活,当然了,他们还是在一直学习着各种算法~ 这天小Hi和小Ho所在的学 ...

  6. AOJ 0531:Paint Color(二维离散+imos)

    [题目链接] http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0531 [题目大意] 给出一张图,和一些矩形障碍物,求该图没被障碍物覆 ...

  7. nyoj_600:花儿朵朵(树状数组+坐标离散化)

    http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...

  8. Atlantis(坐标离散化)

    http://poj.org/problem?id=1151 题意:给出矩形的左上角坐标和右下角坐标(坐标的y轴是向下的),求出矩形面积的并.. 今天好困啊..迷迷糊糊的听会神给讲了讲,敲完之后调试了 ...

  9. nyoj 600:花儿朵朵(树状数组+坐标离散化)

    http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...

随机推荐

  1. python---django中orm的使用(2)

    1.基于对象的正向查询和反向查询 在python---django中orm的使用(1)中也提到了正向和反向查找 表:一对多  书籍和出版社 class Book(models.Model): titl ...

  2. JVM调优命令-jps

    JVM Process Status Tool,显示指定系统内所有的HotSpot虚拟机进程. 命令格式 1 jps [options] [hostid] options参数-l : 输出主类全名或j ...

  3. SQL语句(七)简单查询

    --简单信息查询 --例1 查询所有学生的信息 --学生 -- Student --所有学生 -- 不限定班级.性别.年龄等条件 --所有信息 -- 所有字段,* select * from stud ...

  4. Spring RedisTemplate操作-ZSet操作(6)

    @Autowired @Resource(name="redisTemplate") private RedisTemplate<String, String> rt; ...

  5. Bower使用笔记

    全局安装bower $ npm install -g bower 检测成功 $ bower help 在项目根目录下进行安装(最新版本),会自动生成一个bower_components文件夹(如果在c ...

  6. python解析minicap

    上篇知道了minicap发送图片的格式,照着官网的app.js代码,改用一个python版的来解析它,适当扩展,可以做个小工具实时显示手机屏幕. 步骤: 一.手机开启minicap服务 adb she ...

  7. javascript构造函数模块

    var Person = (function(){ var Constr; Constr = function(){ this.name = 'carl'; } Constr.prototype = ...

  8. javascript实现的拖拽回放

    这个功能很简单,直接贴代码啊: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...

  9. Linux - awk 文本处理工具五

    awk 线上处理常用模式 awk 处理复杂日志 6.19: DHB_014_号百总机服务业务日报:广州 到达数异常! DHB_023_号百漏话提醒日报:珠海 到达数异常! 6.20: DHB_014_ ...

  10. Windows::Docker::Ubuntu 做 SLAM

    如题,这是一件很蛋疼的事情. 为了完成这一件事情,需要达成目标: Ubuntu GUI 必须要能够显示. Ubuntu 可以链接 USB Camera. 目标一 目标1很容易达成. 在 Win10 中 ...