USACO 5.3 Window Area
Window Area
IV Balkan Olympiad
You've just be assigned the project of implemented a windowing interface. This windowing interface is fairly simple, and fortunately, you don't have to display the actual windows. There are 5 basic operations:
- Create a window
- Bring a window to the top
- Put a window to the bottom
- Destroy a window
- Output what percentage of a window is visible (i.e., isn't covered by windows above it).
In the input, the operations appear in the following format:
- Create window: w(I,x,y,X,Y)
- Bring window to top: t(I)
- Put window on bottom: b(I)
- Destroy window: d(I)
- Output percentage visible: s(I)
The I is a unique identifier for each window, which is one character. The character can be any of 'a'..'z', 'A'..'Z', and '0'..'9'. No extra spaces will appear in the input.
(x,y) and (X,Y) are opposite corners of the window. When a window is created, it is put `on top'. You can't create a window with an identifier that is already in use, but you can destroy a window and then create a new one with the identifier of the destroyed window. Coordinates will be positive integers, and all windows will be of non-zero area (x != X and y != Y). The x and y coordinates are between 1 and 32767 inclusive.
PROGRAM NAME: window
INPUT FORMAT
The input file consists of a sequence of commands to your interpreter. They will be listed one per line. Terminate the program when no more input is available
SAMPLE INPUT (file window.in)
w(a,10,132,20,12)
w(b,8,76,124,15)
s(a)
OUTPUT FORMAT
Output lines only for the s() commands. Of course, there might be several s() commands (but no more than 500) so the output should be a sequence of percentages, one per line, stating the percentage of the windows that are visible. The percentages should be rounded to 3 decimal places.
SAMPLE OUTPUT (file window.out)
49.167
——————————————————————————————题解
借用USACO的字符画一下
*----------------*
| |
| |
| |
| *----* |
| | | |
| | | |
| | | |
| *----* |
| |
| |
*----------------*
||
\/
*-----*----*-----*
| | | |
| | 2 | |
| | | |
| *----* |
| | | |
| 1 | | 3 |
| | | |
| *----* |
| | 4 | |
| | | |
*-----*----*-----* *-----*
| 2 |
| |
*------------------*
| |
| |
*------------------*
| 4 |
| |
*-----* *------------*
| |
*-------| |
| | |
| | |
| 1 *------------*
| | 4 |
*-------*---* 这样上下左右的切割,递归处理
前四个操作只要记录一下高度值,修改高度就可以了
/*
ID: ivorysi
LANG: C++
PROG: window
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <string.h>
#include <cmath>
#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 0x3f3f3f3f
#define ivorysi
#define mo 97797977
#define hash 974711
#define base 47
#define pss pair<string,string>
#define MAXN 5000
#define fi first
#define se second
#define pii pair<int,int>
#define esp 1e-8
typedef long long ll;
using namespace std;
char a[];
int f,cut[];
int cnt;
struct data{
int lx,ly,rx,ry;
int h;
}window[];
int calc(char c) {
if(c>='a' && c<='z') return c-'a'+;
else if (c>='A' && c<='Z') return c-'A'+;
else if(c>='' && c<='') return c-''+;
}
void ins(int x,int y,int X,int Y,char c) {
int t=calc(c);
++cnt;
window[t].lx=min(x,X);
window[t].ly=min(y,Y);
window[t].rx=max(x,X);
window[t].ry=max(y,Y);
window[t].h=;
siji(i,,) {//这里原来打成xiaosiji忘改了
if(window[i].h!= && i!=t) ++window[i].h;
}
}
void top(char c) {
int t=calc(c);
int he=window[t].h;
window[t].h=;
siji(i,,) {
if(window[i].h!= && window[i].h<he && i!=t) ++window[i].h;
}
}
void del(char c) {
int t=calc(c);
int he=window[t].h;
window[t].h=;
siji(i,,) {
if(window[i].h!= && window[i].h>he) --window[i].h;
}
}
void bottom(char c) {
int t=calc(c);
int he=window[t].h;
window[t].h=cnt;
siji(i,,) {
if(window[i].h!= && window[i].h>he && i!=t) --window[i].h;
}
}
int solute(int k,int x1,int y1,int x2,int y2) {
if(x2<=x1 || y2<=y1) return ;
int t=k;
while(t>&&(window[cut[t]].rx <=x1 || window[cut[t]].ry<=y1
|| window[cut[t]].lx>=x2 || window[cut[t]].ly>=y2)) --t;
if(t<=) return (x2-x1)*(y2-y1); int res=;
if(window[cut[t]].lx>x1) {
res+=solute(t-,x1,y1,window[cut[t]].lx,y2);
}
if(window[cut[t]].ly>y1) {
res+=solute(t-,max(x1,window[cut[t]].lx),y1,min(x2,window[cut[t]].rx),window[cut[t]].ly);
}
if(window[cut[t]].rx<x2) {
res+=solute(t-,window[cut[t]].rx,y1,x2,y2);
}
if(window[cut[t]].ry<y2) {
res+=solute(t-,max(x1,window[cut[t]].lx),window[cut[t]].ry,min(x2,window[cut[t]].rx),y2);
}
return res;
}
void solve() {
int x1,y1,x2,y2;
while(scanf("%s",a+)!=EOF) {
if(a[]=='w') {
siji(i,,strlen(a+)) {
if(a[i]<'' || a[i] > '') a[i]=' ';
}
sscanf(a+,"%d%d%d%d",&x1,&y1,&x2,&y2);
ins(x1,y1,x2,y2,a[]);
}
else if(a[]=='t') {
top(a[]);
}
else if(a[]=='b') {
bottom(a[]);
}
else if(a[]=='d') {
del(a[]);
}
else {
f=;
int t=calc(a[]);
if(window[t].h==) {puts("0.000");continue;} siji(i,,) {
if(window[t].h>window[i].h && window[i].h!=) cut[++f]=i;
}
int sa=solute(f,window[t].lx,window[t].ly,window[t].rx,window[t].ry);
int sb=(window[t].ry-window[t].ly)*(window[t].rx-window[t].lx);
printf("%.3lf\n",(double)sa/sb*);
}
}
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("window.in","r",stdin);
freopen("window.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}
USACO 5.3 Window Area的更多相关文章
- [洛谷P2745] [USACO5.3]窗体面积Window Area
洛谷题目链接:[USACO5.3]窗体面积Window Area 题目描述 你刚刚接手一项窗体界面工程.窗体界面还算简单,而且幸运的是,你不必显示实际的窗体.有 5 种基本操作: 创建一个新窗体 将窗 ...
- luogu【P2745】[USACO5.3]窗体面积Window Area
这个题 就是个工程题 (然而一开始我并不知道怎么做..还是看nocow的..qwq)(原题入口) 算法为 离散化 + 扫描线 将大坐标变小 并且 用横纵坐标进行扫描 来计算面积 一开始 我想边添加 ...
- USACO 5.3 章节
相关讲解可在USACO上看原文,也可以搜索nocow找到翻译的! (nocow上有些微翻译是有问题的,如果想看nocow翻译的建议也对着英文看) 以下记录以下 自己之前未掌握的一些要点,以及按自己的括 ...
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
- 转:SDL2源代码分析
1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...
- Using SetWindowRgn
Using SetWindowRgn Home Back To Tips Page Introduction There are lots of interesting reasons for cre ...
- SDL2源码分析2:窗体(SDL_Window)
===================================================== SDL源码分析系列文章列表: SDL2源码分析1:初始化(SDL_Init()) SDL2源 ...
- FFmpeg源代码简单分析:libavdevice的gdigrab
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- SDL2源代码分析2:窗口(SDL_Window)
===================================================== SDL源代码分析系列文章列表: SDL2源代码分析1:初始化(SDL_Init()) SDL ...
随机推荐
- Hadoop生态圈-Hbase过滤器(Filter)
Hadoop生态圈-Hbase过滤器(Filter) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.
- 博世传感器调试笔记(三)加速度及地磁传感器BMC156
一. 器件简介:1. BMC 156是一款整合三轴地磁传感器与三轴(12bit)加速度传感器于一体的传感器,以BMC 150 电子罗盘模块为基础, 并与Bosch Sensortec 2x ...
- COGS 513 八
513. 八 http://www.cogs.pro/cogs/problem/problem.php?pid=513 ★☆ 输入文件:eight.in 输出文件:eight.out 简单 ...
- 【重要】Nginx模块Lua-Nginx-Module学习笔记(三)Nginx + Lua + Redis 已安装成功(非openresty 方式安装)
源码地址:https://github.com/Tinywan/Lua-Nginx-Redis 一. 目标 使用Redis做分布式缓存:使用lua API来访问redis缓存:使用nginx向客户端提 ...
- Java并发编程原理与实战十四:Lock接口的认识和使用
保证线程安全演进: synchronized volatile AtomicInteger Lock接口提供的方法: void lock():加锁 void unlock():解锁 void lock ...
- 你需要了解 Windows Phone 8.1 的11件事
微软已经发布了其新一代手机操作系统 Windows Phone 8.1,拥有一些新的特性.从本质上来说,微软此次的大修让 Windows Phone 更接近 Android 和 iOS,对于使用体验的 ...
- 配置SpringBoot-从日志系统配置说起
大小系统都需要打日志. 系统在不同环境下对日志的配置要求是不一样的 比如 开发本地: 直接输出到控制台 生产环境: 输出到文件或者额外的日志收集系统, 比如 graylog. (本文不探讨具体日志系统 ...
- HDU 1717 小数化分数2 数学题
解题报告:输入一个小于1的小数,让你把这个数转化成分数,但注意,输入的数据还有无限循环的小数,循环节用一对括号包含起来. 之前还没有写过小数转分数的题,当然如果没有循环小数的话,应该比较简单,但是这题 ...
- 逆序对 inversion
评测传送门 [问题描述] 有一个1 − n的排列,你会依次进行m次操作,第i次操作表示为(x i , y i ),交换以这两个 值为下标的元素,每次操作有一半的概率成功,你需要求出最后序列的逆序对 ...
- 2016.6.17——Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array 本题收获: 1.“删除”数组中元素 2.数组输出 题目: Given a sorted array, remove the du ...