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 ...
随机推荐
- Java基础-引用数据类型之集合(Collection)
Java基础-引用数据类型之集合(Collection) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.为什么出现集合类 面向对象语言对事物的体现都是以对象的形式,所以为了方便 ...
- 视音频数据处理入门:UDP-RTP协议解析
===================================================== 视音频数据处理入门系列文章: 视音频数据处理入门:RGB.YUV像素数据处理 视音频数据处理 ...
- Jekins - Hello world,Jekins + Maven + Git + Tomcat 的简单应用
Java Web 工程 新建一个简单的 Java Web 工程,并提交至 GitHub,可参考 Eclipse 提交工程至 GitHub 下载 jekins.war 在 http://mirrors. ...
- idea 常用快捷使用
一.智能提示 1.快速移动到错误代码 :Shift+F2 或者 f2/ 2.快速修复:Alt+Enter 3.快速生成括号:Ctrl+Shift+Enter 二.重构 1.重构功能汇总:Ctrl+Sh ...
- Android 动态添加Spinner(.java文件内实现) 实现 改变spinner 内文字属性
动态添加spinner 控件 Spinner s = new Spinner(this); String []items={"自己定义的要显示的数组"}; my_SpinnerAd ...
- Personal idea
我的设想是在android上开发一款应用程序,整体上是一个指南针的样式,或许你可以称之为一个圆盘,在不同的场景下可以作为不同的功能,指南针,游戏转盘,数字转盘等等.界面可以在不同的情境下更换样式.
- Celery异步任务队列/周期任务+ RabbitMQ + Django
一.Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celer ...
- windows程序设计.窗口.
第一个windows窗口 #include <windows.h> /* Displays "Hello, World!" in client area */ LRES ...
- 《区块链100问》第85集:资产代币化之对标美元USDT
USDT是Tether公司推出的对标美元(USD)的代币Tether USD.1USDT=1美元,用户可以随时使用USDT与USD进行1:1兑换.Tether公司执行1:1准备金保证制度,即每个USD ...
- 排序算法的java实现
冒泡.选择就不写了.很常见 一:插入排序: /** * 插入排序 */ public class P4_3 { static void insertSort(int[] a){ int j,t; /* ...