-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1008.cpp
More file actions
124 lines (105 loc) · 1.94 KB
/
1008.cpp
File metadata and controls
124 lines (105 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>
using namespace std;
#define maxn 1022
const int xx[4] = { 1, 0, -1, 0 };
const int yy[4] = { 0, 1, 0, -1 };
const char rr[4] = { 'R', 'T', 'L', 'B' };
int n, m, quex[maxn * maxn], quey[maxn * maxn], s, t, hx, hy, sum;
bool tutu[maxn][maxn] = { 0 }, used[maxn][maxn] = { 0 };
int pre(int x) {
++x;
if (x == maxn * maxn)
x = 0;
return x;
}
void work1() {
int x, y;
hx = maxn;
hy = maxn;
for (int i = 1; i <= n; ++i) {
cin >> x;
cin >> y;
tutu[x][y] = true;
if (x < hx || (x == hx && y < hy)) {
hx = x;
hy = y;
}
}
s = 0, t = 1;
quex[1] = hx;
quey[1] = hy;
used[hx][hy] = true;
cout << hx << " " << hy << endl;
while (pre(t) != s) {
s = pre(s);
hx = quex[s];
hy = quey[s];
for (int i = 0; i < 4; ++i)
if (tutu[hx + xx[i]][hy + yy[i]] && !used[hx + xx[i]][hy + yy[i]]) {
char v = rr[i];
cout << v;
t = pre(t);
quex[t] = hx + xx[i];
quey[t] = hy + yy[i];
used[hx + xx[i]][hy + yy[i]] = true;
}
if (s != t)cout << "," << endl;
else {
cout << "." << endl;
return;
}
}
}
void work2() {
cin >> m;
tutu[n][m] = true;
sum = 1;
s = 0, t = 1;
quex[1] = n;
quey[1] = m;
char ch;
cin >> ch;
while (ch != '.') {
s = pre(s);
hx = quex[s];
hy = quey[s];
while (ch != ',') {
t = pre(t);
++sum;
if (ch == 'R') {
tutu[hx + 1][hy] = true;
quex[t] = hx + 1;
quey[t] = hy;
}
else if (ch == 'T') {
tutu[hx][hy + 1] = true;
quex[t] = hx;
quey[t] = hy + 1;
}
else if (ch == 'L') {
tutu[hx - 1][hy] = true;
quex[t] = hx - 1;
quey[t] = hy;
}
else if (ch == 'B') {
tutu[hx][hy - 1] = true;
quex[t] = hx;
quey[t] = hy - 1;
}
cin >> ch;
}
cin >> ch;
}
cout << sum << endl;
for (int i = 1; i <= 10; ++i) {
for (int j = 1; j <= 10; ++j)
if (tutu[i][j])
cout << i << " " << j << endl;
}
}
int main() {
cin >> n;
if (getchar() == '\n') work1();
else work2();
return 0;
}