procedure2012
It's not worth it to know you're not worth it!

[题目来源]:Beijing 2008

[关键字]:模拟

[题目大意]:用字符的形式给出n窗口,以他的编号作为它的边(中间是空的),找出所有在最上层的窗口。

//=====================================================================================================

[分析]:先找到每一个窗口的左上角,如果找不到则必不可能是最顶上的,然后利用左上角找到可能的宽和长,再以此判断此长和宽是否成立(没有其他窗口覆盖)。

[代码]:

View Code
 1 program Project1;
2 var
3 p: array[0..200,0..200] of char;
4 c: array['A'..'Z'] of boolean;
5 n, m: longint;
6
7 procedure init;
8 var
9 i, j: longint;
10 begin
11 readln(n,m);
12 if (n = 0) and (m = 0) then exit;
13 for i := 1 to n do
14 begin
15 for j := 1 to m do read(p[i,j]);
16 readln;
17 end;
18 {for i := 1 to n do
19 begin
20 for j := 1 to m do write(p[i,j]);
21 writeln;
22 end; }
23 end;
24
25 function done(x, y: longint; id: char):boolean;
26 var
27 xx, yy, wi, hi, wii, hii, i, j: longint;
28 begin
29 if p[x+1,y] <> id then exit(false);
30 if p[x,y+1] <> id then exit(false);
31 // writeln(id);
32
33 wi := 0;
34 hi := 0;
35 for i := y to m do
36 if p[x,i] = id then inc(wi) else break;
37 for i := x to n do
38 if p[i,y] = id then inc(hi) else break;
39 // writeln(id,'',wi,'',hi);
40
41 wii := 0;
42 hii := 0;
43 xx := x+hi-1;
44 yy := y+wi-1;
45 for i := y to m do
46 if p[xx,i] = id then inc(wii) else break;
47 if wii <> wi then exit(false);
48 for i := x to n do
49 if p[i,yy] = id then inc(hii) else break;
50 if hii <> hi then exit(false);
51
52 for i := x+1 to xx-1 do
53 for j := y+1 to yy-1 do
54 if p[i,j] <> '.' then exit(false);
55
56 exit(true);
57 end;
58
59 procedure work;
60 var
61 i, j: longint;
62 ch: char;
63 begin
64 fillchar(c,sizeof(c),false);
65 for i := 1 to n do
66 for j := 1 to m do
67 if p[i,j] in ['A'..'Z'] then
68 if done(i,j,p[i,j]) then
69 c[p[i,j]] := true;
70 for ch := 'A' to 'Z' do
71 if c[ch] then write(ch);
72 writeln;
73 //readln;
74 end;
75
76 begin
77 while 1 = 1 do
78 begin
79 init;
80 if (n = 0) and (m = 0) then break;
81 work;
82 end;
83 end.



posted on 2011-11-02 08:28  procedure2012  阅读(241)  评论(0编辑  收藏  举报