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

思路:第一反应是二维线段树,代码又臭又长,可以做。但是这题暴力+离散化就可以过。可以看到他给的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 ;
}

ZOJ 2747 Paint the Wall(离散化+暴力)题解的更多相关文章

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

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

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

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

  3. Paint the Wall ZOJ - 2747

    点数很多,坐标值很大,然后离散化一下用一个点表示一小块的面积对应的颜色,然后更新的时候一块一块更新,查询的时候一块一块查询 #include<map> #include<set> ...

  4. ZOJ 3790 Consecutive Blocks (离散化 + 暴力)

    题目链接 虽然是一道暴力的题目,但是思路不好想.刚开始还超时,剪枝了以后1200ms,不知道为什么还是这么慢. 题意:给你n个点,每个点有一种颜色ci,给你至多k次删除操作,每次删除一个点,问最多k次 ...

  5. ZOJ - 3781 Paint the Grid Reloaded 题解

    题目大意: 给一个n*m的X O构成的格子,对一个点操作可以使与它相连通的所有一样颜色的格子翻转颜色(X—>O或O—>X),问给定的矩阵最少操作多少次可以全部变成一样的颜色. 思路: 1. ...

  6. ZOJ 3781 Paint the Grid Reloaded(BFS+缩点思想)

    Paint the Grid Reloaded Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N rows ...

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

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

  8. ZOJ Monthly, June 2014 月赛BCDEFGH题题解

    比赛链接:点击打开链接 上来先搞了f.c,,然后发现状态不正确,一下午都是脑洞大开,, 无脑wa,无脑ce...一样的错犯2次.. 硬着头皮搞了几发,最后20分钟码了一下G,不知道为什么把1直接当成不 ...

  9. ZOJ 3781 - Paint the Grid Reloaded - [DFS连通块缩点建图+BFS求深度][第11届浙江省赛F题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Time Limit: 2 Seconds      Me ...

随机推荐

  1. sencha touch 入门系列 (一)sencha touch 简介

    参考链接:http://mobile.51cto.com/others-278381.htm Sencha touch 是基于JavaScript编写的Ajax框架ExtJS,将现有的ExtJS整合J ...

  2. install kubernetes dashboard 安装 kubernetes dashboard 详细

    参考: http://www.bubuko.com/infodetail-2242562.html http://www.cnblogs.com/zhenyuyaodidiao/p/6500897.h ...

  3. windows环境下最简单的nginx + tomcat负载均衡配置示例

    后端是两台tomcat服务器,我们简称为node1 和node2,访问地址分别是 http://192.168.1.2:8080 和 http://192.168.1.4:8080 前端使用nginx ...

  4. 【BZOJ5085】最大 鸽巢原理

    [BZOJ5085]最大 Description 给你一个n×m的矩形,要你找一个子矩形,价值为左上角左下角右上角右下角这四个数的最小值,要你最大化矩形的价值. Input 第一行两个数n,m,接下来 ...

  5. {sharepoint} SetPermission

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsof ...

  6. 神兽保佑-代码无BUG

    ┏┓ ┏┓┏┛┻━━━┛┻┓┃ ┃ ┃ ━ ┃┃ ┳┛ ┗┳ ┃┃ ┃┃ ┻ ┃┃ ┃┗━┓ ┏━┛ ┃ ┃   神兽保佑 ┃ ┃   代码无BUG!       ┃ ┗━━━┓       ┃ ┣┓ ...

  7. 微信小程序 --- 绘画

    cavans及context详解 绘画API的使用 游戏的制作

  8. Hive桶列BucketedTables

    The CLUSTERED BY and SORTED BY creation commands do not affect how data is inserted into a table – o ...

  9. (贪心)kruskal思想

    hdu4313 Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  10. 170515、mybatis批量操作

    //Java代码 public void batchAdd(){ SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession(); Stud ...