Posted on 2008-04-08 13:05
superman 阅读(355)
评论(0) 编辑 收藏 引用 所属分类:
URAL
1 /* Accepted 0.015 212 KB */
2 #include <queue>
3 #include <cctype>
4 #include <string>
5 #include <iostream>
6
7 using namespace std;
8
9 struct pixel { int x, y; };
10
11 int main()
12 {
13 int n, x, y;
14 bool map[12][12] = {false};
15
16 cin >> n;
17 if(cin.get() == '\n')
18 {
19 int sx, sy;
20 cin >> sx >> sy;
21 cout << sx << ' ' << sy << endl;
22
23 map[sx][sy] = true;
24 while(cin >> x >> y)
25 map[x][y] = true;
26
27 pixel cur = {sx, sy};
28 queue <pixel> q;
29 q.push(cur);
30
31 while(q.empty() == false)
32 {
33 n--;
34 cur = q.front(); q.pop();
35 map[cur.x][cur.y] = false;
36 if(map[cur.x + 1][cur.y])
37 {
38 cout << 'R';
39 map[cur.x + 1][cur.y] = false;
40 pixel tmp = {cur.x + 1, cur.y};
41 q.push(tmp);
42 }
43 if(map[cur.x][cur.y + 1])
44 {
45 cout << 'T';
46 map[cur.x][cur.y + 1] = false;
47 pixel tmp = {cur.x, cur.y + 1};
48 q.push(tmp);
49 }
50 if(map[cur.x - 1][cur.y])
51 {
52 cout << 'L';
53 map[cur.x - 1][cur.y] = false;
54 pixel tmp = {cur.x - 1, cur.y};
55 q.push(tmp);
56 }
57 if(map[cur.x][cur.y - 1])
58 {
59 cout << 'B';
60 map[cur.x][cur.y - 1] = false;
61 pixel tmp = {cur.x, cur.y - 1};
62 q.push(tmp);
63 }
64 cout << (n ? ',' : '.') << endl;
65 }
66 }
67 else
68 {
69 int x = n, y, cnt = 0; cin >> y;
70 pixel cur = {x, y};
71
72 queue <pixel> q;
73 q.push(cur);
74
75 string s;
76 while(q.empty() == false)
77 {
78 cnt++;
79 cin >> s;
80 cur = q.front(); q.pop();
81 map[cur.x][cur.y] = true;
82 for(int i = 0; isalpha(s[i]); i++)
83 {
84 if(s[i] == 'R')
85 {
86 pixel tmp = {cur.x + 1, cur.y};
87 q.push(tmp);
88 }
89 if(s[i] == 'T')
90 {
91 pixel tmp = {cur.x, cur.y + 1};
92 q.push(tmp);
93 }
94 if(s[i] == 'L')
95 {
96 pixel tmp = {cur.x - 1, cur.y};
97 q.push(tmp);
98 }
99 if(s[i] == 'B')
100 {
101 pixel tmp = {cur.x, cur.y - 1};
102 q.push(tmp);
103 }
104 }
105 }
106 cout << cnt << endl;
107 for(int i = 1; i <= 10; i++)
108 for(int j = 1; j <= 10; j++)
109 if(map[i][j])
110 cout << i << ' ' << j << endl;
111 }
112
113 return 0;
114 }
115