1 #include<iostream>
2 using namespace std;
3 struct Rect
4 {
5 int x1,y1,x2,y2;//分别为左上角和右下角(左上角为最小的横纵坐标)
6 int level;//标识符
7 int s;//面积为0表示不存在
8 }rect[100],que[50000],now;
9 int Max,Min;
10 int front,rail;
11 int cal(char a)
12 {
13 if(a<='9'&&a>='0')return a-'0';
14 if(a<='Z'&&a>='A')return a-'A'+10;
15 if(a<='z'&&a>='a')return a-'a'+36;
16 }
17 void t(char a)
18 {
19 rect[cal(a)].level=++Max;
20 }
21 void b(char a)
22 {
23 rect[cal(a)].level=--Min;
24 }
25 void d(char a)
26 {
27 rect[cal(a)].s=0;
28 }
29 void w(char a,int x1,int y1,int x2,int y2)
30 {
31 t(a);
32 rect[cal(a)].x1=x1;
33 rect[cal(a)].x2=x2;
34 rect[cal(a)].y1=y1;
35 rect[cal(a)].y2=y2;
36 rect[cal(a)].s=(y2-y1)*(x2-x1);
37 }
38 bool cross(int x1,int x2,int x3,int x4)//两条线段 x1-x2,x3-x4
39 {
40 if(x2<=x3||x4<=x1)return false;
41 return true;
42 }
43 void add(int x1,int y1,int x2,int y2,int level)
44 {
45 que[rail].x1=x1;
46 que[rail].x2=x2;
47 que[rail].y1=y1;
48 que[rail].y2=y2;
49 que[rail].level=level;
50 rail++;
51 }
52 void cut(int x1,int y1,int x2,int y2,int dir,int k,int level)
53 {
54 int k1,k2;
55 switch(dir)
56 {
57 //先从x方向切
58 case 1:
59 {
60 k1=max(x1,rect[k].x1);
61 k2=min(x2,rect[k].x2);
62 if(x1<k1)add(x1,y1,k1,y2,level);
63 if(k2<x2)add(k2,y1,x2,y2,level);
64 cut(k1,y1,k2,y2,dir+1,k,level);
65 break;
66 }
67 //再从y方向切
68 case 2:
69 {
70 k1=max(y1,rect[k].y1);
71 k2=min(y2,rect[k].y2);
72 if(y1<k1)add(x1,y1,x2,k1,level);
73 if(k2<y2)add(x1,k2,x2,y2,level);
74 }
75 }
76 }
77 void s(char a)
78 {
79 front=0;
80 rail=1;
81 que[0]=rect[cal(a)];
82 for(int k=0;k<62;++k)
83 {
84 if(rect[k].s==0)continue;
85 if(rect[k].level<=rect[cal(a)].level)continue;
86 int j=rail,i=front;
87 while(i!=j)
88 {
89 now=que[front++];
90 if(cross(now.x1,now.x2,rect[k].x1,rect[k].x2)&&cross(now.y1,now.y2,rect[k].y1,rect[k].y2))
91 cut(now.x1,now.y1,now.x2,now.y2,1,k,now.level);
92 else add(now.x1,now.y1,now.x2,now.y2,now.level);
93 i++;
94 }
95 }
96 int sum=0;
97 for(int s=front;s<rail;++s)
98 sum+=(que[s].y2-que[s].y1)*(que[s].x2-que[s].x1);
99 printf("%.3lf\n",(double)sum/(double)rect[cal(a)].s*100.0);
100 }
101 int main()
102 {
103 freopen("window.in","r",stdin);
104 freopen("window.out","w",stdout);
105 char tmp;
106 char a;
107 int x1,y1,x2,y2;
108 Max=Min=0;
109 while(1)
110 {
111 if(scanf("%c",&tmp)==-1)break;
112 if(tmp=='w')
113 {
114 scanf("(%c,%d,%d,%d,%d)",&a,&x1,&y1,&x2,&y2);
115 if(x1>x2)swap(x1,x2);
116 if(y1>y2)swap(y1,y2);
117 w(a,x1,y1,x2,y2);
118 }
119 else if(tmp=='t')
120 {
121 scanf("(%c)",&a);
122 t(a);
123 }
124 else if(tmp=='b')
125 {
126 scanf("(%c)",&a);
127 b(a);
128 }
129 else if(tmp=='d')
130 {
131 scanf("(%c)",&a);
132 d(a);
133 }
134 else if(tmp=='s')
135 {
136 scanf("(%c)",&a);
137 s(a);
138 }
139 getchar();
140 }
141 return 0;
142 }