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 ...
随机推荐
- maven添加docker插件无法引入,运行时报错 No plugin found for prefix 'docker'
maven 安装不上docker插件,运行 提示:docker:bulid时No plugin found for prefix 'docker' 原因是maven不能识别 docker-maven- ...
- Linux清屏命令
1:clear 2:Ctrl+L 3:printf "\033c" 4:ALT+F8 By KillerLegend Ref:http://www.coolcoder.in/201 ...
- Android 6.0 7.0 8.0 一个简单的app内更新版本-okgo app版本更新
登陆时splash初始页调用接口检查app版本.如有更新,使用okGo的文件下载,保存到指定位置,调用Android安装apk. <!-- Android 8.0 (Android O)为了针对 ...
- CSS3 颜色模式
HSL .test{background-color:hsl(<length>, <percentage>, <percentage>);} 1.length 表示 ...
- angularJS $http $q $promise
一天早晨,爹对儿子说:“宝儿,出去看看天气如何!” 每个星期天的早晨,爹都叫小宝拿着超级望远镜去家附近最高的山头上看看天气走势如何,小宝说没问题,我们可以认为小宝在离开家的时候给了他爹一个promis ...
- No known class method for selector 'setImage:andName:'错误分析.//删除.h与.m文件时的注意事项
CHENYILONG Blog No known class method for selector 'setImage:andName:'错误分析.//删除.h与.m文件时的注意事项 ...
- linux下lz4解压缩遇到的那些事儿
一.Debian系列:Debian.Ubuntu等1.1 kali下修改apt-get源: vim /etc/apt/sources.list deb http://mirrors.ust ...
- Vue的生命周期的介绍
[推荐链接] https://segmentfault.com/a/1190000008010666
- Python练习-生成器-一个生成器被坑的体无完肤
代码如下,尽可能独立阅读: # 编辑者:闫龙 from urllib.request import urlopen #导入一个包,这就是egon留的一个坑 def get(url):#这是为了保证题目 ...
- pom可以过滤resource 下的文件