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

题目大意&&解答戳:❀

 #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. 函数和常用模块【day06】:模块特殊变量(十四)

    from test import test ''' __mame__ # 当前文件为主文件是等于__main__.用于调用时不执行一些命令 __file__ # 当前文件的路径,相对路径 __cach ...

  2. dynamic

    dynamic的特性很多,好像和反射也有关,不过这里先介绍一个特性,关于反射的再补充. 我们来看一个方法: public virtual ActionResult Insert(T info) 有一个 ...

  3. AttributeError: 'module' object has no attribute 'X509_up_ref'

    主要报错: AttributeError: 'module' object has no attribute 'X509_up_ref' 1 解决办法 卸载再重装pyOpenSSL pip unins ...

  4. bzoj千题计划248:bzoj3697: 采药人的路径

    http://www.lydsy.com/JudgeOnline/problem.php?id=3697 点分治 路径0改为路径-1 g[i][0/1] 和 f[i][0/1]分别表示当前子树 和 已 ...

  5. Docker 入门 第一部分: 定位和设置

    目录 Docker 入门 第一部分: 定位和设置 Docker概念 镜像和容器 容器和虚拟机 准备你的Docker环境 测试 Docker 的版本 测试 Docker 安装 回顾 总结 Docker ...

  6. AngularJs -- 内置指令

    AngularJS提供了一系列内置指令.其中一些指令重载了原生的HTML元素,比如<form>和<a>标签, 当在HTML中使用标签时,并不一定能明确看出是否在使用指令. 其他 ...

  7. getopts 用法

    getopts是linux系统中的一个内置变量,一般用在循环中.每当执行循环是,getopts都会检查下一个命令选项,如果这些选项出现在option中,则表示是合法选项,否则不是合法选项.并将这些合法 ...

  8. 20165227 2017-2018-2《Java程序设计》课程总结

    20165227 2017-2018-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1 简要内容: 记忆深刻的老师 我期望的师生关系 对于Java学习的看法 预备作业2 简要内 ...

  9. usb_control_msg函数用法和说明

    usb_control_msg是没有用到urb的在USB中简单进行发送和接收的一种机制,用于少量的数据通信.原型为:  程序代码 linux+v2.6.35/drivers/usb/core/mess ...

  10. springcloud中的负载均衡策略

    IRule 这是所有负载均衡策略的父接口,里边的核心方法就是choose方法,用来选择一个服务实例. AbstractLoadBalancerRule AbstractLoadBalancerRule ...