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

题目大意&&解答戳:

 #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. Git 配置环境及常用命令整理

    一.Git教程网站 廖雪峰网站 易百GitHub命令:https://www.yiibai.com/git/git_clone.html 完成Windows环境命令下Git config配置 设置好之 ...

  2. bzoj千题计划189:bzoj1867: [Noi1999]钉子和小球

    http://www.lydsy.com/JudgeOnline/problem.php?id=1867 dp[i][j] 落到(i,j)的方案数 dp[i][j]=0.5*dp[i-1][j]   ...

  3. elasticsearch-dump 迁移es数据 (elasticdump)

    elasticsearch 部分查询语句 # 获取集群的节点列表: curl 'localhost:9200/_cat/nodes?v' # 列出所有索引: curl 'localhost:9200/ ...

  4. Oozie 生成JMS消息并向 JMS Provider发送消息过程分析

    一,涉及到的工程 从官网下载源码,mvn 编译成 Eclipse工程文件:

  5. Yii 自定义模型路径

    例如现有两个 Yii 项目,分别是 test1 和 test2.在 test1 中,已经有模型了,test2 直接调用 test1 中的模型,其实添加个别名,然后修改下配置即可. 先在 index.p ...

  6. Python网络通信 (一)

    ISO(国际标准化组织)--->网络体系结构标准 OSI模型 OSI 七层模型 应用层 :提供用户服务,具体内容由特定程序规定 表示层 :提供数据的压缩解压和加密等 会话层 :建立程序级的连接, ...

  7. Android View坐标系详解(getTop()、getX、getTranslationX...)

    View 提供了如下 5 种方法获取 View 的坐标:1. View.getTop().View.getLeft().View.getBottom().View.getRight();2. View ...

  8. 微信小程序入门与实战

    1. 备注:并不是真的不需要下载,只是下载的包小于1MB,给人的感觉像是不用下载 2. 3. 理论上:同一级可以有无限个,纵向只能有五级 目前小程序分包大小有以下限制: 整个小程序所有分包大小不超过 ...

  9. python日常

    1.远程访问远程访问Jupyter Notebook,本地浏览器不能打开,先查了防火墙的状态,然后将设置的端口进行allow,网址,仍然拒绝链接,而后通过远程访问Jupyter Notebook,然后 ...

  10. Visual C++中最常用的类与API函数

    这篇文章能让初学者快速了解visual C++ MFC中常见的核心的类与函数,虽然全部看下来有点枯燥,但对初学者快速了解MFC的框架结构很有好处. 常用类 CArchive类:用于二进制保存档案 CB ...