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 ...
随机推荐
- Sql Server 优化技巧
1.查看执行时间和cpu占用时间 set statistics time on select * from dbo.Product set statistics time off 打开你查询之后的消息 ...
- 递归和静态static
function sum($n){ if($==1){ return 1; } return $n+sum($n-1); } echo sum(100); ---------------------- ...
- bzoj千题计划154:bzoj3343: 教主的魔法
http://www.lydsy.com/JudgeOnline/problem.php?id=3343 high记录原始身高 HIGH记录每块排序之后的身高 不满一块的直接对high操作,重排之后再 ...
- win7启动apache-activemq报错及解决办法
win7启动apache-activemq报错,如下: jvm 1 |jvm 1 | Java Runtime: Oracle Corporation 1.8.0_74 C:\Program File ...
- ASP.NET项目与IE10、IE11不兼容的解决办法
1.解决办法 机器级别修复, 服务器所有ASP.NET程序受益 需要去微软下载对应asp.NET版本的修补程序 .NET 4 -http://support.microsoft.com/kb/2600 ...
- 20155235 2016-2017-2 《Java程序设计》第六周学习总结
20155235 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 第十章 InputStream与OutputStreaam 串流设计的概念 串流继承架构 川 ...
- vue组件之间传值方式解析
vue组件之间传值方式解析一.父组件传到子组件 1.父组件parent代码如下: <template> <div class="parent"> <h ...
- hdu 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) M ...
- xmlHttpRequest 跨域和上传或下载进度条
跨域 XMLHttpRequest 请求 普通网页能够使用XMLHttpRequest对象发送或者接受服务器数据, 但是它们受限于同源策略. 扩展可以不受该限制. 任何扩展只要它先获取了跨域请求许可, ...
- 洛谷 P4559: bzoj 5319: [JSOI2018]军训列队
题目传送门:洛谷 P4559. 题意简述: 有 \(n\) 个学生,编号为 \(i\) 的学生有一个位置 \(a_i\). 有 \(m\) 个询问,每次询问编号在 \([l,r]\) 区间内的学生跑到 ...