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 ...
随机推荐
- java基础-引用数据类型之一维数组(Array)
java基础-引用数据类型之一维数组(Array) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.数组的定义 1>.为什么需要数组 保存一个数据可以定义一个变量,如果要保 ...
- Java基础-正则表达式(Regular Expression)语法规则简介
Java基础-正则表达式(Regular Expression)语法规则简介 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.正则表达式的概念 正则表达式(Regular Exp ...
- 笔记 jquery 的一个bug解决方法积累
本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处 当id或匹配条件中包含特殊字符时,浏览器控制台会报缺少")"的异常,解决办法目前有两个: ...
- linux服务器上没有jar命令
在linux服务器上用jar命令解压jar包时,提示找不到jar命令. 但是用java -version查看jdk版本,又可以显示出jdk版本. echo $JAVA_HOME查看环境变量路径,找不到 ...
- CSS3 颜色模式
HSL .test{background-color:hsl(<length>, <percentage>, <percentage>);} 1.length 表示 ...
- flask配置日志输出文件
1.flask可以通过日志库来指点日志输出的路径, 配置日志输出的连接:www.gaodin.com
- Scrapy爬虫框架之爬取校花网图片
Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络抓取 )所设 ...
- JS踩过的坑
一:DOM对象的查找 DOM的查找到的对象,除byID的之外,返回的都是一个数组,并不是DOM对象无法调用DOM对象的方法. 通过id查找: 因为id在一个HTML文件中唯一,因此查找到的只会是一个元 ...
- Redis简介——(一)
1.关于关系型数据库和nosql数据库 关系型数据库是基于关系表的数据库,最终会将数据持久化到磁盘上,而nosql数据 库是基于特殊的结构,并将数据存储到内存的数据库.从性能上而言,nosql数据库 ...
- ActiveMQ实现消息的发送与接受
activemq是apache的一个JMS接口的实现产品,java中定义了JMS规范,虽然RocketMQ,kafka现在比较火,但是还是建议先学一下activeMQ再学其他两个就容易很多 首先可以下 ...