题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积。

思路:第一反应是二维线段树,代码又臭又长,可以做。但是这题暴力+离散化就可以过。可以看到他给的n只有100,也就是说最坏情况下会涂100次,每次最多涂200*200个点,那么完全可以用暴力。有一个地方纠结了半天,原题每一格代表了面积,我们离散化后每一格代表的是坐标点,所以我在涂面积时在起始位置+1后的位置开始涂,在算面积时,坐标左边就是涂的面积。

代码:

#include<set>
#include<map>
#include<cstdio>
#include<utility>
#include<cmath>
#include<stack>
#include<vector>
#include<queue>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<algorithm>
#define ll long long
#define ull unsigned long long
using namespace std;
const int maxn = +;
const int seed = ;
const int MOD = ;
const int INF = 0x3f3f3f3f;
struct node{
int x1,y1,x2,y2,color;
}q[maxn];
int x[maxn << ],y[maxn << ]; //离散
int mp[maxn << ][maxn << ];
int color[maxn];
int main(){
int h,w;
int n,Case = ;
while(~scanf("%d%d",&h,&w) && h + w){
scanf("%d",&n);
int num1 = ,num2 = ;
for(int i = ;i <= n;i++){
scanf("%d%d%d%d%d",&q[i].x1,&q[i].y1,&q[i].x2,&q[i].y2,&q[i].color);
x[num1++] = q[i].x1,x[num1++] = q[i].x2;
y[num2++] = q[i].y1,y[num2++] = q[i].y2;
}
sort(x,x + num1);
sort(y,y + num2);
num1 = unique(x,x + num1) - x;
num2 = unique(y,y + num2) - y;
memset(mp,,sizeof(mp));
memset(color,,sizeof(color));
for(int k = ;k <= n;k++){
int x1 = lower_bound(x,x + num1,q[k].x1) - x;
int x2 = lower_bound(x,x + num1,q[k].x2) - x;
int y1 = lower_bound(y,y + num2,q[k].y1) - y;
int y2 = lower_bound(y,y + num2,q[k].y2) - y;
for(int i = x1 + ;i <= x2;i++){
for(int j = y1 + ;j <= y2;j++){
mp[i][j] = q[k].color;
}
}
}
for(int i = ;i < num1;i++){
for(int j = ;j <= num2;j++){
if(mp[i][j]){
color[mp[i][j]] += (x[i] - x[i - ])*(y[j] - y[j - ]);
}
}
}
if(Case != ) printf("\n");
printf("Case %d:\n",Case++);
int num = ;
for(int i = ;i <= ;i++){
if(color[i]){
printf("%d %d\n",i,color[i]);
num++;
}
}
if(num == ){
printf("There is 1 color left on the wall.\n");
}
else{
printf("There are %d colors left on the wall.\n",num);
}
}
return ;
}

最新文章

  1. jQuery经典学习笔记
  2. re正则表达式16_managing complex regexes
  3. eclipse-4.4.2安装Groovy插件(其他版本eclipse可参考)
  4. Windows 7中使用Eclipse 使用CDT and WinGW 开发C/C++(转载)
  5. C# 之 遍历本地文件夹下的所有文件
  6. locale 详解
  7. iOS 图片转NSData-b
  8. KAFKA分布式消息系统[转]
  9. java笔记9之switch
  10. XSS初体验
  11. Java基础——数据类型
  12. js实现最短时间走完不同速度的路程
  13. window10下安装linux虚拟机
  14. [git]checkout&amp;branch
  15. Python全栈之路----进制运算
  16. rpc和http
  17. Android UI系列-----ImageView的scaleType属性
  18. 【pyqtgraph绘图】线条,填充和颜色
  19. 查看mysql版本
  20. JavaScript系列文章:谈谈let和const

热门文章

  1. Excel 2010 统计行数
  2. 【BZOJ2901】矩阵求和
  3. Unity3D笔记四 基础知识概念
  4. [MongoDB] 用户权限管理
  5. [转]CentOS 6.4下Squid代理服务器的安装与配置
  6. Centos6.5安装JDK环境
  7. LaTeX:Question &amp; Answer
  8. tensorflow和python操作中的笔记
  9. HDU_1457_后缀自动机四&#183;重复旋律7
  10. HTML5-Canvas 图形变换+状态保存