ZOJ 2747 Paint the Wall(离散化+暴力)题解
题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积。
思路:第一反应是二维线段树,代码又臭又长,可以做。但是这题暴力+离散化就可以过。可以看到他给的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(离散化+暴力)题解的更多相关文章
- 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Paint the Wall ZOJ - 2747
点数很多,坐标值很大,然后离散化一下用一个点表示一小块的面积对应的颜色,然后更新的时候一块一块更新,查询的时候一块一块查询 #include<map> #include<set> ...
- ZOJ 3790 Consecutive Blocks (离散化 + 暴力)
题目链接 虽然是一道暴力的题目,但是思路不好想.刚开始还超时,剪枝了以后1200ms,不知道为什么还是这么慢. 题意:给你n个点,每个点有一种颜色ci,给你至多k次删除操作,每次删除一个点,问最多k次 ...
- ZOJ - 3781 Paint the Grid Reloaded 题解
题目大意: 给一个n*m的X O构成的格子,对一个点操作可以使与它相连通的所有一样颜色的格子翻转颜色(X—>O或O—>X),问给定的矩阵最少操作多少次可以全部变成一样的颜色. 思路: 1. ...
- 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 ...
- HDU 4391 - Paint The Wall - 分块哈希入门
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意 : 给一段区间, 有两种操作 1 : 给 x 到 y 的区间染色为 z 2 : 查询 ...
- ZOJ Monthly, June 2014 月赛BCDEFGH题题解
比赛链接:点击打开链接 上来先搞了f.c,,然后发现状态不正确,一下午都是脑洞大开,, 无脑wa,无脑ce...一样的错犯2次.. 硬着头皮搞了几发,最后20分钟码了一下G,不知道为什么把1直接当成不 ...
- 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 ...
随机推荐
- TCP协议的基本规则和在Java中的使用
TCP协议是面向连接的,相对于UDP协议来说效率较低,但是比较安全,数据不容易丢失.TCP协议类似打电话的过程,在一端拨号时必须等待对方回应,确定两端建立了连接通道才能传送信息. 在Java中TCP被 ...
- executeQuery、executeUpdate 和 execute
Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 1. Resul ...
- hdu 5318 The Goddess Of The Moon
The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- 【Wannafly挑战赛4】F 线路规划 倍增+Kruskal+归并
[Wannafly挑战赛4]F 线路规划 题目描述 Q国的监察院是一个神秘的组织.这个组织掌握了整个帝国的地下力量,监察着Q国的每一个人.监察院一共有N个成员,每一个成员都有且仅有1个直接上司,而他只 ...
- 170731、Nginx初探
一. 概念 Nginx——Ngine X,是一款自由的.开源的.高性能HTTP服务器和反向代理服务器:也是一个IMAP.POP3.SMTP代理服务器:也就是说Nginx本身就可以托管网站(类似于Tom ...
- 公民身份号码校验码算法(C#版)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- hdu6386 Age of Moyu【最短路】
Age of Moyu Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) To ...
- Python+ Calibre 处理 中文报纸
import re ##2 line='<a href=nw.D110000renmrb_20180401_1-01.htm><script>document.write(vi ...
- 向Docx4j生成的word文档中添加布局--第二部分
原文标题:Adding layout to your Docx4j-generated word documents, part 2 原文链接:http://blog.iprofs.nl/2012/1 ...
- Python大数据:信用卡逾期分析
# -*- coding:utf-8 -*- # 数据集成 import csv import numpy as np import pandas as pd import matplotlib.py ...