http://acm.hdu.edu.cn/showproblem.php?pid=1543

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 10000
using namespace std; int h,w,n;
int X[maxn],Y[maxn],m[][],clo[maxn];
struct node
{
int x1,y1,x2,y2,c;
}p[maxn*]; int bs(int key,int l,int r,int a[])
{
int low=l,high=r;
while(low<=high)
{
int mid=(low+high)>>;
if(a[mid]==key)
{
return mid;
}
if(a[mid]<key)
low=mid+;
else if(a[mid]>key)
high=mid-;
}
}
int main()
{
int case1=;
while(scanf("%d%d",&h,&w)!=EOF)
{
if(h==&&w==) break;
scanf("%d",&n);
int x1,y1,x2,y2,c;
int t=;
memset(X,,sizeof(X));
memset(Y,,sizeof(Y));
for(int i=; i<n; i++)
{
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&c);
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
p[i].x1=x1;p[i].x2=x2;p[i].y1=y1;p[i].y2=y2;p[i].c=c;
X[t]=x1;Y[t++]=y1;
X[t]=x2;Y[t++]=y2;
}
sort(X,X+t);
sort(Y,Y+t);
int t1=,t2=;
memset(m,,sizeof(m));
for(int i=; i<t; i++) if(X[i]!=X[i-]) X[t1++]=X[i];
for(int i=; i<t; i++) if(Y[i]!=Y[i-]) Y[t2++]=Y[i];
for(int i=; i<n; i++)
{
int xx1=bs(p[i].x1,,t1-,X);
int yy1=bs(p[i].y1,,t2-,Y);
int xx2=bs(p[i].x2,,t1-,X);
int yy2=bs(p[i].y2,,t2-,Y);
for(int j=xx1; j<xx2; j++)
{
for(int k=yy1; k<yy2; k++)
{
m[j][k]=p[i].c;
}
}
}
memset(clo,,sizeof(clo));
for(int i=; i<t1; i++)
{
for(int j=; j<t2; j++)
{
if(m[i][j])
{
clo[m[i][j]]+=(X[i+]-X[i])*(Y[j+]-Y[j]);
}
}
}
int t3=;
if(case1) printf("\n");
printf("Case %d:\n",++case1);
for(int i=; i<=; i++)
{
if(clo[i]) {t3++;printf("%d %d\n",i,clo[i]);}
}
if(t3==)
{
printf("There is 1 color left on the wall.\n");
}
else
printf("There are %d colors left on the wall.\n",t3); }
}

hdu 1543 Paint the Wall的更多相关文章

  1. HDU 4391 Paint The Wall(分块+延迟标记)

    Paint The Wall Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4391 - Paint The Wall - 分块哈希入门

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意 : 给一段区间, 有两种操作 1 : 给 x 到 y 的区间染色为 z 2 : 查询 ...

  3. HDU 4391 Paint The Wall 段树(水

    意甲冠军: 特定n多头排列.m操作 以下是各点的颜色 以下m一种操纵: 1 l r col 染色 2 l r col 问间隔col色点 == 通的操作+区间内最大最小颜色数的优化,感觉非常不科学... ...

  4. HDU 4391 Paint The Wall(分块的区间维护)

    题意:给出几个操作,把l-r赋值为z,询问l-r有几个z,其中z < INT_MAX 思路:因为z很大,所以很难直接用线段树去维护.这里可以使用分块来解决.我们可以让每个块用map去储存map[ ...

  5. 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543

    学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...

  6. HDU 4012 Paint on a Wall(状压+bfs)

    Paint on a Wall Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  7. hdu 3669 Cross the Wall(斜率优化DP)

    题目连接:hdu 3669 Cross the Wall 题意: 现在有一面无限大的墙,现在有n个人,每个人都能看成一个矩形,宽是w,高是h,现在这n个人要通过这面墙,现在只能让你挖k个洞,每个洞不能 ...

  8. HDU 2124 Repair the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...

  9. --hdu 2124 Repair the Wall(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...

随机推荐

  1. python:redis简单操作

    一,安装redis-py pip install redis easy_install redis 二,简单用法 import redis # 连接redis服务器 def conn_redis(): ...

  2. 解决多线程下simpleDateFormat的安全问题

    // 日期格式化 private static final ThreadLocal<SimpleDateFormat> GMT_FORMATERS = new ThreadLocal< ...

  3. escape encodeURI encodeURIComponent区别

    escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串.使用unescape来解码. 有效的URI(统一资源标示符)是不能包含某些字符的,如空格,所以需要进行编码,编码方法有 ...

  4. 负载均衡之DNS轮询

    大多数域名注册商都支持对统一主机添加多条A记录,这就是DNS轮询,DNS服务器将解析请求按照A记录的顺序,随机分配到不同的IP上,这样就完成了简单的负载均衡.下图的例子是:有3台联通服务器.3台电信服 ...

  5. Debian编译内核

    转自 yuzibo博客 http://yuzibo.github.io/DebianBuildKernel.html 最终成功一次了 之前又一次编译了好多次.可惜没有一次成功的,说实话.借助Debia ...

  6. 修改用户的home路径

    1.直接修改/etc/passwd文件 2.usermod -d /hadoop -u 1531 附:usermod详细参数 语 法:usermod [-LU][-c <备注>][-d & ...

  7. Java类与类之间关系总结

    继承,依赖,关联,聚合,组合 一般来说依赖和关联是类似的,关联是强依赖,聚合和组合是一类,组合属于强聚合. 继承:一般是子类和父类之间的关系,关键字extends 依赖:可以这样记忆,做某件事必须要依 ...

  8. Javascipt 时间格式化(日期)

    Date.prototype.format =function(format){ var o = { "M+" : this.getMonth()+1, //month " ...

  9. linux的make install命令

    tar zxvf redis-2.8.15.tar.gz cd redis-2.8.15/ make make test make install

  10. sqlyog使用注意事项

    在sqlyog中执行sql语句时,如果sql语句没有加limit 0,1000; sqlyog会自动查询从0开始的1000条,结果导致mysql慢查系统中显示的sql语句末尾加上了limit 0,10 ...