/*
PROG: window
LANG: C++
*/
#include
<
cstdio
>
#include
<
cstring
>
using
namespace
std;
const
int
maxn
=
128
;
int
n,head,tail;
char
s[
50
];
int
prev[maxn],next[maxn];
int
x1[maxn],y1[maxn],x2[maxn],y2[maxn];
void
swap(
int
&
x,
int
&
y)
{
int
tmp
=
x;
x
=
y;
y
=
tmp;
}
void
addhead()
{
prev[n]
=-
1
;
next[n]
=
head;
if
(head
!=-
1
) prev[head]
=
n;
head
=
n;
if
(tail
==-
1
) tail
=
n;
}
void
addtail()
{
next[n]
=-
1
;
prev[n]
=
tail;
if
(tail
!=-
1
) next[tail]
=
n;
tail
=
n;
if
(head
==-
1
) head
=
n;
}
void
move()
{
if
(n
!=
head) next[prev[n]]
=
next[n];
if
(n
!=
tail) prev[next[n]]
=
prev[n];
if
(n
==
head) head
=
next[n];
if
(n
==
tail) tail
=
prev[n];
}
double
cut(
int
x,
int
y,
int
l,
int
r,
int
z)
{
while
(z
!=-
1
&&
(x
>=
x2[z]
||
y
>=
y2[z]
||
l
<=
x1[z]
||
r
<=
y1[z]))
z
=
next[z];
if
(z
==-
1
)
return
(l
-
x)
*
(r
-
y);
double
res
=
0
;
if
(x
<
x1[z]){
res
+=
cut(x,y,x1[z],r,next[z]);
x
=
x1[z];
}
if
(l
>
x2[z]){
res
+=
cut(x2[z],y,l,r,next[z]);
l
=
x2[z];
}
if
(y
<
y1[z])
res
+=
cut(x,y,l,y1[z],next[z]);
if
(r
>
y2[z])
res
+=
cut(x,y2[z],l,r,next[z]);
return
res;
}
void
solve_w()
{
sscanf(s
+
4
,
"
%d,%d,%d,%d
"
,x1
+
n,y1
+
n,x2
+
n,y2
+
n);
if
(x2[n]
<
x1[n]) swap(x1[n],x2[n]);
if
(y2[n]
<
y1[n]) swap(y1[n],y2[n]);
addtail();
}
void
solve_t()
{
move();
addtail();
}
void
solve_b()
{
move();
addhead();
}
void
solve_d()
{
move();
}
void
solve_s()
{
double
ans
=
cut(x1[n],y1[n],x2[n],y2[n],next[n]);
printf(
"
%0.3lf\n
"
,
100.0
*
(ans
/
((x2[n]
-
x1[n])
*
(y2[n]
-
y1[n]))));
}
void
solve()
{
n
=
s[
2
];
switch
(s[
0
]){
case
'
w
'
:
solve_w();
break
;
case
'
t
'
:
solve_t();
break
;
case
'
b
'
:
solve_b();
break
;
case
'
d
'
:
solve_d();
break
;
case
'
s
'
:
solve_s();
}
}
int
main()
{
freopen(
"
window.in
"
,
"
r
"
,stdin);
freopen(
"
window.out
"
,
"
w
"
,stdout);
head
=
tail
=-
1
;
memset(prev,
-
1
,
sizeof
(prev));
memset(next,
-
1
,
sizeof
(next));
do
{
scanf(
"
%s\n
"
,s);
solve();
}
while
(
!
feof(stdin));
return
0
;
}
/*
Executing
Test 1: TEST OK [0.011 secs, 2804 KB]
Test 2: TEST OK [0.011 secs, 2804 KB]
Test 3: TEST OK [0.000 secs, 2804 KB]
Test 4: TEST OK [0.011 secs, 2804 KB]
Test 5: TEST OK [0.000 secs, 2804 KB]
Test 6: TEST OK [0.000 secs, 2804 KB]
Test 7: TEST OK [0.000 secs, 2804 KB]
Test 8: TEST OK [0.000 secs, 2804 KB]
Test 9: TEST OK [0.000 secs, 2804 KB]
Test 10: TEST OK [0.011 secs, 2804 KB]
Test 11: TEST OK [0.011 secs, 2804 KB]
*/
posted on 2009-07-23 13:53
xfstart07 阅读(136)
评论(0) 编辑 收藏 引用