usaco 5.3 Window Area(模拟+矩形切割)
来源:互联网 发布:广州用友java面试题 编辑:程序博客网 时间:2024/06/06 13:07
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)
(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
题目:让你模拟一些窗口的创建移动等操作,输出每次给定窗口的可见度。。。
分析:由于数据相当的小,直接模拟就行,面积的计算用矩形切割就行,现在发现矩形切割对于数据小的题还是很好用的。。。。
代码:
/*ID: 15114582PROG: windowLANG: C++*/#include<cstdio>#include<cstring>#include<iostream>using namespace std;struct win{ int l,r,t,b;}w[999];int live[256],p[999];int bot,top,x1,y1,x2,y2;double see;char op,id,s[256];void cut(int i,int l,int r,int t,int b){ while(i<top&&(r<=w[i].l||l>=w[i].r||b<=w[i].t||t>=w[i].b))++i; if(i>=top)see+=(r-l)*(b-t); else { if(l<w[i].l)cut(i+1,l,w[i].l,t,b),l=w[i].l; if(r>w[i].r)cut(i+1,w[i].r,r,t,b),r=w[i].r; if(t<w[i].t)cut(i+1,l,r,t,w[i].t); if(b>w[i].b)cut(i+1,l,r,w[i].b,b); }}int main(){ freopen("window.in","r",stdin); freopen("window.out","w",stdout); memset(live,0,sizeof(live)); memset(p,0,sizeof(p)); bot=top=256; while(~scanf("%s",s)) { if(s[0]=='w') { sscanf(s,"%c(%c,%d,%d,%d,%d)",&op,&id,&x1,&y1,&x2,&y2); if(x1>x2)swap(x1,x2); if(y1>y2)swap(y1,y2); w[top].l=y1,w[top].r=y2; w[top].t=x1,w[top].b=x2; live[id]=top; p[top++]=id; } if(s[0]=='t') { for(int i=live[s[2]];i<top-1;++i) { swap(live[p[i]],live[p[i+1]]); swap(p[i],p[i+1]); swap(w[i],w[i+1]); } } if(s[0]=='b') { for(int i=live[s[2]];i>bot;--i) { swap(live[p[i]],live[p[i-1]]); swap(p[i],p[i-1]); swap(w[i],w[i-1]); } } if(s[0]=='d') { for(int i=live[s[2]];i<top-1;++i) { swap(live[p[i]],live[p[i+1]]); swap(p[i],p[i+1]); swap(w[i],w[i+1]); } --top; } if(s[0]=='s') { int i=live[s[2]]; double sum=(w[i].r-w[i].l)*(w[i].b-w[i].t); see=0; cut(i+1,w[i].l,w[i].r,w[i].t,w[i].b); printf("%.3lf\n",see/sum*100); } } return 0;}
- usaco 5.3 Window Area(模拟+矩形切割)
- USACO Section 5.3 Window Area - 又一矩形覆盖问题
- USACO 5.3 Window Area
- USACO Section 5.3 Window Area
- usaco 5.3.2 Window Area
- USACO Window Area 解题报告
- C++——【USACO 5.3.2】——Window Area
- usaco Section 3.1 Shaping Regions -- 矩形切割
- USACO 6.2.3 shaping regions 矩形切割
- CSS特殊样式(一)模拟波浪线+矩形切割
- usaco window arear(递归求矩形覆盖面积)
- Section 5.3 window area
- [URAL 1147][USACO rect1]Shaping Regions(矩形切割)
- USACO Shaping Regions,难题,离散化,矩形切割,逆序染色
- usaco Transformations (矩形翻转||模拟题)
- 矩形切割
- 矩形切割
- 线段切割&&矩形切割
- C#反射
- #ifndef与#pragma once
- LoadImage BitBlt 学习笔记
- 关于内存对齐
- C语言实现去除字符串中空格
- usaco 5.3 Window Area(模拟+矩形切割)
- 企业资本运营,让老板淡出个人神话
- MCU(单片机)现在各种接口都有哎呀!
- 无法打开预编译头文件的解决方法及预编译头原理
- linux awk命令
- Linux下Fork与Exec使用
- 关于爱情
- 日期选择控件
- 【ZT】DXUTGUI控件的定制