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. C#中枚举类型和int类型的转化

    先定义一个枚举类型 , 初中, 高中,大学 }; int ->enum int d=2; PropertyType  a=(PropertyType)d; int <- enum Prop ...

  2. Object-C 点语法 -- 笔记

    第一种是经典方式, 第一种是点语法.

  3. Android中自定义Activity和Dialog的位置大小背景和透明度等

    1.自定义Activity显示样式 先在res/values下建colors.xml文件,写入: view plainprint? 1. <?xml version="1.0" ...

  4. VNC 黑屏

    参考资料: http://blog.sina.com.cn/s/blog_57edaf600100serf.html http://www.programgo.com/article/43581885 ...

  5. css过渡+3D

    <!DOCTYPE html><html><head> <title>guodu</title> <meta charset=&quo ...

  6. CI框架深入篇(2)一些基础的我之不知道的标准格式

    1,一些命名规则:类文件名必大写,其他配置文件,视图文件或着脚本都要小写,类文件名和类名要一致!! 2,类名要大写开头,若是多个单词,那就下划线不要驼封法: 3,变量名要小写全,多个单词下划线分割,后 ...

  7. rpm命令数据库修复日志

    今天在linux安装软件过程中遇到了一个小坑,rpm数据库被破坏: 状况: #rpm -qa | grep rpm 返回: [解决方案] 删除旧数据库,然后重建数据库: 删除旧数据库: # rm /v ...

  8. grep,awk和sed

    commons: all of them could use regular-expression to match the result. differences: 1)grep: search f ...

  9. Linux shell 脚本中”2>&1″的含义解释

    脚本是:nohup /mnt/Nand3/H2000G  >/dev/null  2>&1 &   对于& 1 更准确的说应该是文件描述符 1,而1 一般代表的就是 ...

  10. The account '' has no team with ID ''

    Xcode 升级到7.2 版本,真机测试的时候报错:The account '' has no team with ID '' 解决办法1:http://stackoverflow.com/quest ...