USACO 6.2 Shaping Regions
Shaping Regions
N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the sheet's borders. All rectangles fall within the borders of the sheet so that different figures of different colors will be seen.
The coordinate system has its origin (0,0) at the sheet's lower left corner with axes parallel to the sheet's borders.
PROGRAM NAME: rect1
INPUT FORMAT
The order of the input lines dictates the order of laying down the rectangles. The first input line is a rectangle "on the bottom".
| Line 1: | A, B, and N, space separated (1 <= A,B <= 10,000) |
| Lines 2-N+1: | Five integers: llx, lly, urx, ury, color: the lower left coordinates and upper right coordinates of the rectangle whose color is `color' (1 <= color <= 2500) to be placed on the white sheet. The color 1 is the same color of white as the sheet upon which the rectangles are placed. |
SAMPLE INPUT (file rect1.in)
20 20 3
2 2 18 18 2
0 8 19 19 3
8 0 10 19 4
INPUT EXPLANATION
Note that the rectangle delineated by 0,0 and 2,2 is two units wide and two high. Here's a schematic diagram of the input:
11111111111111111111
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
11222222442222222211
11222222442222222211
11222222442222222211
11222222442222222211
11222222442222222211
11222222442222222211
11111111441111111111
11111111441111111111
The '4's at 8,0 to 10,19 are only two wide, not three (i.e., the grid contains a 4 at 8,0 and a 4 at 8,1 but NOT a 4 at 8,2 since this diagram can't capture what would be shown on graph paper).
OUTPUT FORMAT
The output file should contain a list of all the colors that can be seen along with the total area of each color that can be seen (even if the regions of color are disjoint), ordered by increasing color. Do not display colors with no area.
SAMPLE OUTPUT (file rect1.out)
1 91
2 84
3 187
4 38 ————————————————————————————————————————————题解
和前面那个窗口题有什么区别……???
/*
ID: ivorysi
LANG: C++
PROG: rect1
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x5f5f5f5f
#define ivorysi
#define mo 97797977
#define hash 974711
#define base 47
#define fi first
#define se second
#define pii pair<int,int>
#define esp 1e-8
typedef long long ll;
using namespace std;
int n,col[],an[];
struct data {
int lx,ly,rx,ry;
}squ[];
int areas(data &t) {
return (t.rx-t.lx+)*(t.ry-t.ly+);
}
void init() {
scanf("%d%d%d",&squ[].rx,&squ[].ry,&n);
--squ[].rx;--squ[].ry;
siji(i,,n) {
scanf("%d%d%d%d",&squ[i].lx,&squ[i].ly,&squ[i].rx,&squ[i].ry);
--squ[i].rx;
--squ[i].ry;
scanf("%d",&col[i]);
}
col[]=;
}
int dfs(int k,data q) {
if(q.rx<q.lx || q.ry<q.ly) return ; int ans=;
while((q.lx>squ[k].rx || q.rx<squ[k].lx || q.ly>squ[k].ry || q.ry<squ[k].ly )&&k<=n) ++k;
if(k>n) return areas(q);
if(q.lx<squ[k].lx)
ans+=dfs(k+,(data){q.lx,max(q.ly,squ[k].ly),squ[k].lx-,min(squ[k].ry,q.ry)});
if(q.rx>squ[k].rx)
ans+=dfs(k+,(data){squ[k].rx+,max(q.ly,squ[k].ly),q.rx,min(squ[k].ry,q.ry)});
if(q.ly<squ[k].ly)
ans+=dfs(k+,(data){q.lx,q.ly,q.rx,squ[k].ly-});
if(q.ry>squ[k].ry)
ans+=dfs(k+,(data){q.lx,squ[k].ry+,q.rx,q.ry});
return ans;
}
void solve() {
init();
siji(i,,n)
an[col[i]]+=dfs(i+,squ[i]);
siji(i,,) if(an[i]!=) printf("%d %d\n",i,an[i]);
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("rect1.in","r",stdin);
freopen("rect1.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}
USACO 6.2 Shaping Regions的更多相关文章
- ural 1147. Shaping Regions
1147. Shaping Regions Time limit: 0.5 secondMemory limit: 64 MB N opaque rectangles (1 ≤ N ≤ 1000) o ...
- ural1147 Shaping Regions
Shaping Regions Time limit: 0.5 secondMemory limit: 64 MB N opaque rectangles (1 ≤ N ≤ 1000) of vari ...
- Shaping Regions(dfs)
Shaping Regions Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 124 Solved: 39[Submit][Status][Web B ...
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
- OI暑假集训游记
莞中OI集训游记 Written BY Jum Leon. I 又是一载夏,本蒟蒻以特长生考入莞中,怀着忐忑的心情到了8月,是集训之际.怀着对算法学习的向往心情被大佬暴虐的一丝恐惧来到了 ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
- [LeetCode] Surrounded Regions 包围区域
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
随机推荐
- python基础-异常(exception)处理
python基础-异常(exception)处理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 程序中难免出现错误,而错误分成两种,即语法错误和逻辑错误.语法错误根本过不了pyth ...
- linux查看tomcat日志
声明:以上内容均为转载,个人对这块知识搜罗之后放在一起,非原创,以后这块有问题还会继续添加. Tomcat 日志分为下面5类: catalina . 相当命令行输出日志 localhost . 相当于 ...
- 2008ZJOI树的统计
codevs 2460 树的统计 http://codevs.cn/problem/2460/ 2008年省队选拔赛浙江 题目等级 : 大师 Master 题目描述 Description 一棵 ...
- 【官方文档】Nginx负载均衡学习笔记(二)负载均衡基本概念介绍
简介 负载均衡(Server Load Balancer)是将访问流量根据转发策略分发到后端多台 ECS 的流量分发控制服务.负载均衡可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应 ...
- 京东全链路压测军演系统(ForceBot)架构解密
摘要:全链路压测是应对电商大促容量规划最有效的手段,如何有效进行容量规划是其中的架构关键问题.京东在全链路压测方面做过多年尝试,本文转载京东商城基础平台技术专家文章,介绍其最新的自动化压测 Force ...
- 微服务深入浅出(4)-- 负载均衡Ribbon
Spring Cloud中可以使用RestTemplate+Ribbon的解决方案来将负载均衡以代码的形式封装到客户端中. 通过查阅官方文档可以知道,只需要在程序的IoC容器中注入一个restTemp ...
- sklearn评估模型的方法
一.acc.recall.F1.混淆矩阵.分类综合报告 1.准确率 第一种方式:accuracy_score # 准确率import numpy as np from sklearn.metrics ...
- Celery异步任务队列/周期任务+ RabbitMQ + Django
一.Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celer ...
- Qbot回归,已感染5.4万台计算机
Qbot回归,已感染5.4万台计算机 近日,BAESystems的安全人员发表了一篇关于Qbot网络感知蠕虫回归的调查报告,指出已经感染了5.4万台计算机. FreeBuf百科 Qbot蠕虫,也叫Qa ...
- [JL]最后的晚餐 动态规划(DP) codevs5318
[JL]最后的晚餐 TimeLimit:1000MS MemoryLimit:1000KB 64-bit integer IO format:%lld Problem Description [题库 ...