Paint the Wall ZOJ - 2747
点数很多,坐标值很大,然后离散化一下用一个点表示一小块的面积对应的颜色,然后更新的时候一块一块更新,查询的时候一块一块查询
#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的更多相关文章
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...
- ZOJ 2747 Paint the Wall(离散化+暴力)题解
题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积. 思路:第一反应是二维线段树,代码又臭又长,可以做.但是这题暴力+离散化就可以过.可以看到他给的n只有100,也就是说最坏情况下会涂10 ...
- 【HDU4391】【块状链表】Paint The Wall
Problem Description As a amateur artist, Xenocide loves painting the wall. The wall can be considere ...
- hdu 1543 Paint the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...
- 【分段哈希】H. Paint the Wall
https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/H [题意] 在一个长为H,宽为W的白墙上选一个矩形区域涂颜色,后涂的颜色会覆盖先 ...
- 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[ ...
随机推荐
- linux下编译upx ucl
昨天,UPX发布了3.93版本. UPX(the Ultimate Packer for eXecutables)是一个非常全面的可执行文件压缩软件,支持dos/exe.dos/com.dos/sys ...
- javascript中的 return false和return true
关于javascript中的 return false和return true,return 是javascript里函数返回值的关键字,一个函数内处理的结果可以使用return 返回,这样在调用函数 ...
- leetcode:Roman to Integer and Integer to Roman
2015-06-03 罗马数字以前接触过I到VIII比较多,直到遇见这个题目才知道更详细.阿拉伯数字和罗马数字之间的转换最重的是了解罗马数字的规则. 罗马数字规则:(总结) 1, 罗马数字共有7个,即 ...
- javascript深入浅出——学习笔记(六种数据类型和隐式转换)
在慕课之前学过JS深入浅出,最近发现很多东西都记不太清楚了,再复习一遍好了,感觉这个课程真的超级棒的,做做笔记,再添加一些学习内容
- springCloud com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
1.com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: c ...
- 简单谈谈数据库DML、DDL和DCL的区别
一.DML DML(data manipulation language)数据操纵语言: 就是我们最经常用到的 SELECT.UPDATE.INSERT.DELETE. 主要用来对数据库的数据进行一些 ...
- python数学第一天【极限存在定理】
1.基本回忆 2.两边夹定理 推论1. 基本三角函数的极限 2.极限存在定理 单调有界数列必有极限 (1)单调递增有上界数列必有极限 (2)单调递减有下界数列必有极限 推论1: (1+1/n)^n有极 ...
- python数据结构与算法第十四天【二分查找】
1.二分查找的原理 对于已经排序的列表进行最快速度的查找 2. 代码实现 (1)递归实现 def binary_search(alist, item): if len(alist) == 0: ret ...
- 老男孩python学习自修【第二天】字符串用法
实时处理增量日志最佳实践 主要使用f.seek()和f.tell()实现 字符串处理函数: s.find(substr, start, end) 查找子字符串,找不到则返回-1,找到则返回对应的索引 ...
- sqlserver数据库性能测试方法
测试计划-添加jdbc jar 地址(数据驱动) jdbc configuration 地址 jdbc:sqlserver://127.0.0.1:1433;databasename=XSData j ...