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. C 计算数组长度

    int data[4],length; length=sizeof(data)/sizeof(data[0]);  //数组占内存总空间除以单个元素占内存空间大小,即等于元素个数 printf(&qu ...

  2. JAVA程序改错 (易错题)

    JAVA程序改错 1. abstract class Name { private String name; public abstract boolean isStupidName(String n ...

  3. ORA-12547:TNS:lost contact 问题分析思路

    ORA-12547:TNS:lost contact sqlplus无法正常登陆数据库 解决思路如下: 1.查看操作系统内核参数是否无误 [oracle@normal adump]$ ulimit - ...

  4. /var子目录

    /var子目录 目录 描述 /var/log/message 日志信息,按周自动轮询 /var/spool/cron/root 定时器配置文件目录,默认按用户命名 /var/log/secure 记录 ...

  5. iOS8及以后 地图定位当前城市

    通过以下网址的步骤实现定位获取城市的功能 http://www.2cto.com/kf/201504/393312.html

  6. java学习之IO对象流

    //注意对象类要打标记实现Serializable接口 package com.gh; import java.io.FileInputStream; import java.io.FileNotFo ...

  7. 基于回调的事件处理——重写onTouchEvent方法响应触摸屏事件

    对于Android提供的事件处理模型,不难发现基于监听的事件处理模型具有更大的优势: 基于监听的事件模型分工更加明确,事件源.事件监听有两个类分开实现,因此具有更好的维护性. Android的事件处理 ...

  8. css 半圆效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. flask基础---第三篇

    flask中request的一些方法 首先from flask import request 1.request.path 2.request.host 3.request.host_url from ...

  10. 乘法DAC一点知识

    在应用电路中发现乘法DAC,以前没有用过所谓的乘法DAC.查过资料发现,其实所有的DAC都可以看作是个“乘法器”-------将输入数字量与基准电压相乘. 一般DAC的输出是VOUT=VREF*D/M ...