hdu 1543 Paint the Wall
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的更多相关文章
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4391 - Paint The Wall - 分块哈希入门
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意 : 给一段区间, 有两种操作 1 : 给 x 到 y 的区间染色为 z 2 : 查询 ...
- HDU 4391 Paint The Wall 段树(水
意甲冠军: 特定n多头排列.m操作 以下是各点的颜色 以下m一种操纵: 1 l r col 染色 2 l r col 问间隔col色点 == 通的操作+区间内最大最小颜色数的优化,感觉非常不科学... ...
- HDU 4391 Paint The Wall(分块的区间维护)
题意:给出几个操作,把l-r赋值为z,询问l-r有几个z,其中z < INT_MAX 思路:因为z很大,所以很难直接用线段树去维护.这里可以使用分块来解决.我们可以让每个块用map去储存map[ ...
- 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...
- 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) ...
- hdu 3669 Cross the Wall(斜率优化DP)
题目连接:hdu 3669 Cross the Wall 题意: 现在有一面无限大的墙,现在有n个人,每个人都能看成一个矩形,宽是w,高是h,现在这n个人要通过这面墙,现在只能让你挖k个洞,每个洞不能 ...
- HDU 2124 Repair the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...
- --hdu 2124 Repair the Wall(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...
随机推荐
- eclipse 32位和64位的jre
让32位Eclipse和64位Eclipse同是在64的Windows7上运行 用文本编辑器打开eclipse.ini文件,在-vmargs之前加入下面的内容: -vm C:\Program Fil ...
- ASP.NET NuGet to install the mvc 5.2.2
http://www.nuget.org/packages/Microsoft.AspNet.Mvc
- JS 实现显示和隐藏div(以百度地图为例)
主要参考的文章:https://my.oschina.net/xsh1208/blog/215811,https://zhidao.baidu.com/question/568774688.html ...
- html5中input新增type值的使用
二狗在最近的项目以html5和webapp为主,并接触到了input新增type值的使用,下面就把这些玩意一一以实例列举出来 一:type = date:定义日期:年-月-日 input type=& ...
- linux杂谈(二十):apache服务配置
1.apache简单介绍 我们常常要浏览网页,提供这种服务是apache.提供apache服务的软件是httpd服务. Apache支持許多特性,大部分通过编译的模块实现.這些特性從伺服器 ...
- 二分-hdu-4768-Flyer
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4768 题目意思: 有n个A.B.C,每个Ai,Bi,Ci,对于每个P=Ai+k*Ci(P<=B ...
- 详述iOS国际化
在真正将国际化实践前,只知道通过NSLocalizedString方法将相应语言的字符串加载进来即可.但最近公司项目的新需求增加英文版本,并支持应用内无死角切换~,这才跳过各种坑实现了应用内切换语言, ...
- logcat使用
做android有些日子了,只是对主要的logcat的具体使用方法还是非常模糊,今天有空,学习一下. logcat能够在adb中使用,也能够直接在命令行下使用. logcat [options] [f ...
- C# Html网页生成图片解决方案1
1.使用System.Windows.Forms命名空间下的WebBrowser控件加载网页并生成图片 GiHub参考地址: https://github.com/tianma3798/FileOpa ...
- handler更新UI主线程
示例:下面代码的功能是修改UI主线程TextView的内容 public class MainActivity extends Activity { private Button btn_start; ...