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:

  1. Create a window
  2. Bring a window to the top
  3. Put a window to the bottom
  4. Destroy a window
  5. 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的更多相关文章

  1. [洛谷P2745] [USACO5.3]窗体面积Window Area

    洛谷题目链接:[USACO5.3]窗体面积Window Area 题目描述 你刚刚接手一项窗体界面工程.窗体界面还算简单,而且幸运的是,你不必显示实际的窗体.有 5 种基本操作: 创建一个新窗体 将窗 ...

  2. luogu【P2745】[USACO5.3]窗体面积Window Area

    这个题 就是个工程题 (然而一开始我并不知道怎么做..还是看nocow的..qwq)(原题入口) 算法为 离散化 + 扫描线  将大坐标变小  并且 用横纵坐标进行扫描 来计算面积 一开始 我想边添加 ...

  3. USACO 5.3 章节

    相关讲解可在USACO上看原文,也可以搜索nocow找到翻译的! (nocow上有些微翻译是有问题的,如果想看nocow翻译的建议也对着英文看) 以下记录以下 自己之前未掌握的一些要点,以及按自己的括 ...

  4. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  5. 转:SDL2源代码分析

    1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...

  6. Using SetWindowRgn

    Using SetWindowRgn Home Back To Tips Page Introduction There are lots of interesting reasons for cre ...

  7. SDL2源码分析2:窗体(SDL_Window)

    ===================================================== SDL源码分析系列文章列表: SDL2源码分析1:初始化(SDL_Init()) SDL2源 ...

  8. FFmpeg源代码简单分析:libavdevice的gdigrab

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  9. SDL2源代码分析2:窗口(SDL_Window)

    ===================================================== SDL源代码分析系列文章列表: SDL2源代码分析1:初始化(SDL_Init()) SDL ...

随机推荐

  1. 科学计算三维可视化---Traits(Property属性)

    Property属性 使用Property函数为类创建Property属性,Property属性用法和一般属性相同,但是他在获取值和赋值时会调用相应的方法 traits库也提供了Property属性 ...

  2. JavaScript中replace()方法的第二个参数解析

    语法 string.replace(searchvalue,newvalue) 参数值 searchvalue 必须.规定子字符串或要替换的模式的 RegExp 对象.请注意,如果该值是一个字符串,则 ...

  3. Spring MVC原理介绍

    1.Spring Web MVC是什么 spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解 ...

  4. 戴尔R720xd服务器系统安装前期环境实现

    型号:R720xd 开启服务器,Ctrl+R进入raid配置 配置完raid后F2对硬盘进行格式化 保存并重启 F11进入BIOS选项设置U盘启动 选择U盘启动 开始进行系统安装!

  5. nginx反向代理下没有获取到正确的clientIP问题发散

    问题背景: 在使用nginx服务器NginxA 来反向代理服务 WebAPIA,WebAPIA中要获取ClientIP,结果获取到的IP为NginxA的, 于是引出了以下的一连串概念... 首先使用X ...

  6. spring——IOC容器BeanFactory和ApplicationContext对比

  7. 20155201 2016-2017-2 《Java程序设计》第六周学习总结

    20155201 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 第十章 输入/输出 字节输入类: Java将输入/输出抽象化为串流,数据有来源及目的地,衔接 ...

  8. 微服务深入浅出(5)-- 声明式调用Feign

    Feign的使用 Feign采用了声明式的API接口的风格,将Java Http客户端绑定到它的内部,从而调用过程变的简单. 配置文件: spring: application: name: eure ...

  9. 天梯赛 L2-013. (并查集) 红色警报

    题目链接 题目描述 战争中保持各个城市间的连通性非常重要.本题要求你编写一个报警程序,当失去一个城市导致国家被分裂为多个无法连通的区域时,就发出红色警报.注意:若该国本来就不完全连通,是分裂的k个区域 ...

  10. MongoDB 查询整理

    查询所有sql:  select * from table_namemongodb:   db.getCollection('期刊论文').find({}) 如上图所示,获取期刊论文collectio ...