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

#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. freemarker之list

    freemarker之list 1.设置数据源 /** * * @Title:student * @Description: * @param:@param name * @return: void ...

  2. Scheme change not implemented

    1.错误描述 2.错误原因 由于在改变Java代码中的方法或运行代码出现,导致Tomcat编译的代码不能替换工作空间的代码,即不能及时同步,出现错误 3.解决办法 (1)关闭Tomcat,clean一 ...

  3. Linux显示计算次数的结果

    Linux显示计算次数的结果 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ free -c free:选项需要一个参数 -- c Usage: free [o ...

  4. OpenStack_I版 3.glance部署

    存储镜像path                 默认镜像不存储在本地,一般放在swift对象存储或Cinder块存储里   glance安装     拷贝配置文件到/ect下,并新建配置目录,日志目 ...

  5. Django学习-10-命名空间

    不使用命名空间,且两个APP某条url使用相同的name属性   app01_urls.py urlpatterns = [ url(r'aaa/$', views.app01_aaa, name=& ...

  6. 各种HTML锚点跳转方式

    1 js控制锚点跳转 <a name="anchor"></a> location.hash="anchor"; 不只有a其他元素也可以 ...

  7. Spring Security验证流程剖析及自定义验证方法

    Spring Security的本质 Spring Security本质上是一连串的Filter, 然后又以一个独立的Filter的形式插入到Filter Chain里,其名为FilterChainP ...

  8. Codeforces Round #424 Div2 E. Cards Sorting

    我只能说真的看不懂题解的做法 我的做法就是线段树维护,毕竟每个数的顺序不变嘛 那么单点维护 区间剩余卡片和最小值 每次知道最小值之后,怎么知道需要修改的位置呢 直接从每种数维护的set找到现在需要修改 ...

  9. Python基础_文件的的处理及异常处理

    今天主要讲讲文件读写及异常处理. 一.文件操作 1.1 文件的创建及读 打开文件 open 函数  open(file,[option]) file 是要打开的文件 option是可选择的参数文件的打 ...

  10. 【BZOJ4650】【NOI2016】优秀的拆分(后缀数组)

    [BZOJ4650][NOI2016]优秀的拆分(后缀数组) 题面 BZOJ Uoj 题解 如果我们知道以某个位置为开始/结尾的\(AA\)串的个数 那就直接做一下乘法就好 这个怎么求? 枚举一个位置 ...