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

#define debug
#include<stdio.h>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<functional>
#include<iomanip>
#include<map>
#include<set>
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>PLL;
typedef pair<int,ll>Pil;
const ll INF = 0x3f3f3f3f;
const double inf=1e8+100;
const double eps=1e-8;
const ll maxn =1e3+200;
const int N = 1e4+10;
const ll mod=1000007;
//
int dx[]= {0,1,-1,0};
int dy[]= {1,0,0,-1};
int fld[2*maxn][2*maxn];
int X1[maxn],X2[maxn],Y1[maxn],Y2[maxn];
int W,H,n;
//
int compress(int *x1,int *x2,int w) {
vector<int>xs;
//
for(int i=0; i<n; i++) {
int tx1=x1[i],tx2=x2[i];
if(1<=tx1&&tx1<w)
xs.push_back(tx1);
if(1<=tx2&&tx2<w)
xs.push_back(tx2);
}
xs.push_back(0);
xs.push_back(w);
sort(xs.begin(),xs.end());
xs.erase(unique(xs.begin(),xs.end()),xs.end());
for(int i=0; i<n; i++) {
x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
cout<<x1[i]<<" "<<x2[i]<<endl;
}
return xs.size()-1;
}
//
int bfs() {
int ans=0;
//
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(fld[i][j])
continue;
ans++;
queue<pair<int,int> >q;
q.push(make_pair(j,i));
while(!q.empty()){
int sx=q.front().first,sy=q.front().second;
q.pop();
//
for(int k=0;k<4;k++){
int tx=sx+dx[k],ty=sy+dy[k];
if(tx<0||W<tx||ty<0||H<ty||fld[ty][tx]>0)
continue;
q.push(make_pair(tx,ty));
fld[ty][tx]=1;
}
}
}
}
return ans;
}
//
void solve() {
int i,j,tt=1;
while(cin>>W>>H) {
cin>>n;
for(i=0; i<n; i++) {
cin>>X1[i]>>Y1[i]>>X2[i]>>Y2[i];
}
memset(fld,0,sizeof(fld));
//
W=compress(X1,X2,W);
H=compress(Y1,Y2,H);
cout<<endl;
for(i=0; i<n; i++) {
cout<<X1[i]<<" "<<Y1[i]<<" "<<X2[i]<<" "<<Y1[i]<<endl;
}
//
for(i=0; i<n; i++) {
fld[Y1[i]][X1[i]]++;
fld[Y2[i]][X2[i]]++;
fld[Y1[i]][X2[i]]--;
fld[Y2[i]][X1[i]]--;
}
//
for(i=0; i<H; i++) {
for(j=1; j<W; j++) {
fld[i][j]+=fld[i][j-1];
}
}
for(i=1; i<H; i++) {
for(j=0; j<W; j++) {
fld[i][j]+=fld[i-1][j];
}
}
for(i=0; i<H; i++) {
for(j=0; j<W; j++) {
cout<<fld[i][j]<<" ";
}
cout<<endl;
}
//
// cout<<bfs()<<endl;
}
} int main() {
ios_base::sync_with_stdio(false);
#ifdef debug
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif
cin.tie(0);
cout.tie(0);
solve();
/*
#ifdef debug
fclose(stdin);
fclose(stdout);
system("out.txt");
#endif
*/
return 0;
}

  

Aizu - 0531 Paint Color的更多相关文章

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

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

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

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

  3. Greedy:Paint Color(AOJ 0531)

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

  4. ProgrammingContestChallengeBook

    POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...

  5. imos-累积和法

    在解AOJ 0531 Paint Color时,学到了一个累积和的妙用--imos法,由于原文是日语,所以特意翻译过来.值得一提的是,作者Kentaro Imajo跟鄙人同龄,却已取得如此多的成就,而 ...

  6. Android Paint画笔及Color .

    引自:http://blog.csdn.net/q445697127/article/details/7736926 Paint paint = new Paint(); // 设置paint为无锯齿 ...

  7. LC 265. Paint House II

    There are a row of n houses, each house can be painted with one of the k colors. The cost of paintin ...

  8. JAVAFX纯手写布局

    主页面效果: 第一栏的效果: 工程目录: package MessageBean; /** * * @author novo */ public class Message { private Str ...

  9. EditBox问题的实现以及Junit测试框架的简要说明

    一.这周的EditBox由一个框改为三个框,同时进行测试,下面给出程序及截图 1 import java.util.regex.Matcher; 2 import java.util.regex.Pa ...

随机推荐

  1. WINDOWS的错误代码对应的故障

    WINDOWS的错误代码对应的故障 0000 操作已成功完成. 0001 错误的函数. 0002 系统找不到指定的文件. 0003 系统找不到指定的路径. 0004 系统无法打开文件. 0005 拒绝 ...

  2. 【原】Java学习笔记031 - 常用类

    package cn.temptation; public class Sample01 { public static void main(String[] args) { /* * 类 Math: ...

  3. hdu2262 Where is the canteen

    Where is the canteen Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  4. iOS - MySQL 的安装配置

    前言 提前下载好相关软件,且安装目录最好安装在全英文路径下.如果路径有中文名,那么可能会出现一些莫名其妙的问题. 提前准备好的软件: mysql-5.7.17-macos10.12-x86_64.dm ...

  5. 关于protected关键字

    protected,算是默认的访问作用域的超集,他们在相同包下时,都可以访问所声明的成员:但对于不同包的访问,默认访问域就不行,protected也必须是通过继承关系来访问. TestBase bas ...

  6. JAVA容器的那些事—集合

    1.首先我们先讲下Collection接口 Collection接口:Collection是最基本的集合接口,它是由一个独立元素所组成的序列,这些元素服务一条或多条规则.一个Collection代表一 ...

  7. Angular通过订阅观察者对象实现不同组件中数据的实时传递

    在angular官方定义中,组件直接的数据交换只要在父子直接传递,但是我们在项目中经常需要在各种层级之间传递数据,下面介绍关于订阅可观察对象实现的数据传递. 首先定义一个服务app.sevice.ts ...

  8. [SPOJ]DISUBSTR:Distinct Substrings&[SPOJ]SUBST1:New Distinct Substrings

    题面 Vjudge Vjudge Sol 求一个串不同子串的个数 每个子串一定是某个后缀的前缀,也就是求所有后缀不同前缀的个数 每来一个后缀\(suf(i)\)就会有,\(len-sa[i]+1\)的 ...

  9. datatable 多字段 排序;

    没有找到datatable的排序方面运用案例,根据接口,自己实现 所以记录一二,小伙伴们有更好的方法,欢迎讨论 1.需求图  2.需求 1)默认 未开启 灰色下箭头 2)第一次点击 :启动排序,降序- ...

  10. 机器学习实战笔记(Python实现)-09-树回归

    ---------------------------------------------------------------------------------------- 本系列文章为<机 ...