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[ ...
随机推荐
- C语言操作WINDOWS系统存储区数字证书相关函数详解及实例
C语言操作WINDOWS系统存储区数字证书相关函数详解及实例 以下代码使用C++实现遍历存储区证书及使用UI选择一个证书 --使用CertOpenSystemStore打开证书存储区. --在循环中 ...
- java中的定时任务小示例
package package_1; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Timer; ...
- vue单页面模板说明文档(1)
Introduction This boilerplate is targeted towards large, serious projects and assumes you are somewh ...
- 面试题(校招java)
1:linux线程和进程的区别? 进程是程序执行时的一个实例,即它是程序已经执行到课中程度的数据结构的汇集.从内核的观点看,进程的目的就是担当分配系统资源(CPU时间.内存等)的基本单位. 线程是进程 ...
- 优化CSS重排重绘与浏览器性能
关于CSS重排和重绘的概念,最近看到不少这方面的文章,觉得挺有用,在制作中考虑浏览器的性能,减少重排能够节省浏览器对其子元素及父类元素的重新渲染:避免过分的重绘也能节省浏览器性能:优化动画,使用3D启 ...
- 解决方法:CentOS7用yum安装软件显示错误:cannot find a valid baseurl for repo: base/7/x86_64
在Linux学习中,发现使用yum安装软件出现以下的错误: 百度了各种方法,很多人也发现光是修改REBOOT=yes也没用,多次进行挂载.修改网卡配置文件.重置IP地址.重启网络.创建又删除配置文件的 ...
- 介绍Ajax与jQuery技术
Ajxs技术(异步的JavaScript与XML)已有多种技术的组合 Ajax的优点是什么? 1.可以实现客户端的异步请求操作2.进而在不需要刷新页面的情况下与服务器进行通信,减少用户的等待时间3.减 ...
- NIO和经典IO
NIO未必更快,在Linux上使用Java6完成的测试中,多线程经典I/O设计胜出NIO30%左右 异步I/O强于经典I/O:服务器需要支持超大量的长期连接,比如10000个连接以上,不过各个客户端并 ...
- Yii2写日志总结
方法一 批量文件配置写入日志: 1. 首先在config.php配置文件中配置log模块 如下: 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, ...
- flask 下载本地文件
下载本地文件就是找到文件路径 调用flask自带的send_file(路径)下载, 并返回 flask: # 下载文件 from flask import send_file@task_mgm.ro ...