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

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
const int mod = 1e9+;
using namespace std; int n, m;
int T, tol;
struct Node {
int x1, y1;
int x2, y2;
int w;
};
Node node[maxn];
int X[maxn];
int Y[maxn];
int maps[maxn][maxn];
int ans[maxn]; void init() {
memset(X, , sizeof X);
memset(Y, , sizeof Y);
memset(ans, , sizeof ans);
memset(node, , sizeof node);
memset(maps, , sizeof maps);
} int main() {
int cas = ;
while(scanf("%d%d", &n, &m), n||m) {
if(cas != ) printf("\n");
init();
int q;
scanf("%d", &q);
int cx = , cy = ;
int x1, y1, x2, y2, w;
int mw = ;
for(int i=; i<=q; i++) {
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &w);
X[cx++] = x1, Y[cy++] = y1;
X[cx++] = x2, Y[cy++] = y2;
node[i].x1 = x1, node[i].y1 = y1;
node[i].x2 = x2, node[i].y2 = y2;
node[i].w = w;
mw = max(mw, w);
}
sort(X, X+cx);
sort(Y, Y+cy);
cx = unique(X, X+cx) - X;
cy = unique(Y, Y+cy) - Y;
// for(int i=0; i<cx; i++) printf("%d%c", X[i], i==cx-1 ? '\n' : ' ');
// for(int i=0; i<cy; i++) printf("%d%c", Y[i], i==cy-1 ? '\n' : ' ');
// printf("\n");
for(int i=; i<=q; i++) {
x1 = lower_bound(X, X+cx, node[i].x1) - X;
x2 = lower_bound(X, X+cx, node[i].x2) - X;
y1 = lower_bound(Y, Y+cy, node[i].y1) - Y;
y2 = lower_bound(Y, Y+cy, node[i].y2) - Y;
// printf("%d %d %d %d\n", x1, y1, x2, y2);
for(int x=x1; x<x2; x++) {
for(int y=y1; y<y2; y++) {
maps[x][y] = node[i].w;
}
}
}
// printf("\n");
// for(int i=0; i<cx; i++) for(int j=0; j<cy; j++) printf("%d%c", maps[i][j], j==cy-1 ? '\n' : ' ');
for(int i=; i<cx; i++) {
for(int j=; j<cy; j++) {
if(!maps[i][j]) continue;
w = maps[i][j];
int area = (X[i+] - X[i]) * (Y[j+] - Y[j]);
ans[w] += area;
}
}
tol = ;
printf("Case %d:\n", cas++);
for(int i=; i<=mw; i++) {
if(ans[i]) {
printf("%d %d\n", i, ans[i]);
tol++;
}
}
if(tol <= ) printf("There is %d color left on the wall.\n", tol);
else printf("There are %d colors left on the wall.\n", tol);
}
return ;
}

Paint the Wall ZOJ - 2747的更多相关文章

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

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

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

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

  3. ZOJ 2747 Paint the Wall(离散化+暴力)题解

    题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积. 思路:第一反应是二维线段树,代码又臭又长,可以做.但是这题暴力+离散化就可以过.可以看到他给的n只有100,也就是说最坏情况下会涂10 ...

  4. 【HDU4391】【块状链表】Paint The Wall

    Problem Description As a amateur artist, Xenocide loves painting the wall. The wall can be considere ...

  5. hdu 1543 Paint the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...

  6. 【分段哈希】H. Paint the Wall

    https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/H [题意] 在一个长为H,宽为W的白墙上选一个矩形区域涂颜色,后涂的颜色会覆盖先 ...

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

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

  8. HDU 4391 Paint The Wall 段树(水

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

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

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

随机推荐

  1. gethostbyname用法

    //会优先查询解析%windir%\system32\drivers\etc\hosts中静态dns表 //一个域名可对应多个IP hostent->h_addr_list ==> 是in ...

  2. package-lock.json和package.json的作用

    转自:https://www.cnblogs.com/cangqinglang/p/8336754.html package-lock.json的作用就是锁定安装依赖时包的版本,并且需要上传到git, ...

  3. cmake : undefined reference to dlopen, dlclose, dlsym and dlerror

    链接出了问题 添加头文件 #include <dlfcn.h> 添加库 target_link_libraries(PROJECT_NAME ${CMAKE_DL_LIBS})

  4. PL/SQL如何调试sql语句、存储过程

    一直以来,我总是在sql的工具,比如sql server.navicat等中执行sql语句来发现问题自己写的sql中的问题,结果被问起时,让人贻笑大方! 那么如何调试成白行的存储过程?如何调试成百行s ...

  5. 重构客户注册-基于ActiveMQ实现短信验证码生产者

    重构目标:将bos_fore项目中的CustomerAction作为短信消息生产者,将消息发给ActiveMQ,创建一个单独的SMS项目,作为短信息的消费者,从ActiveMQ获取短信消息,调用第三方 ...

  6. Programming好文解读系列(—)——代码整洁之道

    注:初入职场,作为一个程序员,要融入项目组的编程风格,渐渐地觉得系统地研究下如何写出整洁而高效的代码还是很有必要的.与在学校时写代码的情况不同,实现某个功能是不难的,需要下功夫的地方在于如何做一些防御 ...

  7. CSS自定义属性expression_r

    CSS的出现使网页制作者在对网页元素的控制方便许多,当然,有利必有弊,CSS只能对颜色.大小.距离等静态样式有效,对于要实现某些html元素的动态样式就显得有些力不从心.有了CSS的自定义属性expr ...

  8. Mysql如何快速插入100万条记录?

    1.java程序拼接insert带多个value,使一次提交多个值. 2.插入数据之前先删除索引(注意主键不能删除),然后插入数据,最后重建索引 3.可以设置手动commit,用来提高效率 4.使用批 ...

  9. mysql 清除大数据表单

    背景:mysql数据库中有个日志表记录高达800多万,影响了mysql的正常业务访问,现需要清理三个月之前的所有数据,大概600多万(大概13G) 方法一:传统delete from xxx,传统,普 ...

  10. js auto hover button & html5 button autofocus

    js auto hover button & html5 button autofocus input // html 5 <input name="myinput" ...