This repository was archived by the owner on May 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1518.cpp
More file actions
53 lines (52 loc) · 1.87 KB
/
P1518.cpp
File metadata and controls
53 lines (52 loc) · 1.87 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
//
// Created by RenAhsAcme on 2026/4/19.
//
#include <iostream>
#include <string>
using namespace std;
int map[10][10];
int main() {
string s;
int fx = 0, fy = 0, cx = 0, cy = 0;
for (int i = 0; i < 10; i++) {
cin >> s;
for (auto j = 0; j < 10; j++) {
if (s[j] == '.') map[i][j] = 0;
else if (s[j] == '*') map[i][j] = 1;
else if (s[j] == 'C') map[i][j] = 2, cx = i, cy = j;
else if (s[j] == 'F') map[i][j] = 3, fx = i, fy = j;
}
}
int cdir = 0, fdir = 0;
int cnt = 0;
while ((cx != fx || cy != fy) && cnt < 1e6) {
if (cdir == 0)
if (cx - 1 >= 0 && map[cx - 1][cy] != 1) map[cx][cy] = 0, map[cx - 1][cy] = 2, cx--;
else cdir = 1;
else if (cdir == 1)
if (cy + 1 < 10 && map[cx][cy + 1] != 1) map[cx][cy] = 0, map[cx][cy + 1] = 2, cy++;
else cdir = 2;
else if (cdir == 2)
if (cx + 1 < 10 && map[cx + 1][cy] != 1) map[cx][cy] = 0, map[cx + 1][cy] = 2, cx++;
else cdir = 3;
else if (cdir == 3)
if (cy - 1 >= 0 && map[cx][cy - 1] != 1) map[cx][cy] = 0, map[cx][cy - 1] = 2, cy--;
else cdir = 0;
if (fdir == 0)
if (fx - 1 >= 0 && map[fx - 1][fy] != 1) map[fx][fy] = 0, map[fx - 1][fy] = 3, fx--;
else fdir = 1;
else if (fdir == 1)
if (fy + 1 < 10 && map[fx][fy + 1] != 1) map[fx][fy] = 0, map[fx][fy + 1] = 3, fy++;
else fdir = 2;
else if (fdir == 2)
if (fx + 1 < 10 && map[fx + 1][fy] != 1) map[fx][fy] = 0, map[fx + 1][fy] = 3, fx++;
else fdir = 3;
else if (fdir == 3)
if (fy - 1 >= 0 && map[fx][fy - 1] != 1) map[fx][fy] = 0, map[fx][fy - 1] = 3, fy--;
else fdir = 0;
cnt++;
}
if (cnt < 1e6) cout << cnt;
else cout << 0;
return 0;
}