Skip to content

Commit

Permalink
went through robothieves
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynng committed Jan 11, 2021
1 parent f88e4bc commit 82936ca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 64 deletions.
1 change: 1 addition & 0 deletions CCC/.cph/.18s3.cpp_48594707a8079a6b73722c42f0195ce8.prob
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Local: 18s3","url":"h:\\GitHub\\Practice\\CCC\\18s3.cpp","tests":[{"id":1610375209160,"input":"","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"h:\\GitHub\\Practice\\CCC\\18s3.cpp","group":"local","local":true}
102 changes: 38 additions & 64 deletions CCC/18s3.cpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
#include <iostream>
using namespace std;
const int maxN = 105;
int n, m, b[maxN][maxN] = { 0 }, sh, sv;
char temp, a[maxN][maxN];
int n, m, dist[maxN][maxN] = { 0 }, ih, iv;
char temp, G[maxN][maxN];
bool u, d, l, r;

void move(int h, int v, int step) {
char current = a[h][v];
if (current == 'W' || (b[h][v] != 0 && b[h][v] <= step)) {
void move(int h, int v, int curDist) {
char current = G[h][v];
if (current == 'W' || (dist[h][v] != 0 && dist[h][v] <= curDist))
return;
}
else {
switch (current) {
case 'U':
b[h][v] = step;
move(h - 1, v, step);
dist[h][v] = curDist;
move(h - 1, v, curDist);
break;
case 'D':
b[h][v] = step;
move(h + 1, v, step);
dist[h][v] = curDist;
move(h + 1, v, curDist);
break;
case 'L':
b[h][v] = step;
move(h, v - 1, step);
dist[h][v] = curDist;
move(h, v - 1, curDist);
break;
case 'R':
b[h][v] = step;
move(h, v + 1, step);
dist[h][v] = curDist;
move(h, v + 1, curDist);
break;
case '.':
case 'S':
b[h][v] = step;
move(h - 1, v, step + 1);
move(h + 1, v, step + 1);
move(h, v - 1, step + 1);
move(h, v + 1, step + 1);
dist[h][v] = curDist;
move(h - 1, v, curDist + 1);
move(h + 1, v, curDist + 1);
move(h, v - 1, curDist + 1);
move(h, v + 1, curDist + 1);
break;
}
}

/*if(direction!='u')move(h + 1, v, 'd');
if (direction != 'd')move(h - 1, v, 'u');
if (direction != 'l')move(h, v + 1, 'r');
if (direction != 'r')move(h, v - 1, 'l');
*/
}


Expand All @@ -52,67 +45,48 @@ int main() {
u = d = l = r = true;
//taking inputs
scanf("%d %d", &n, &m);
/*for (int i = 0; i <= m; i++) {
scanf("%c", &temp);
}
for (int i = 0; i < n - 2; i++) {
scanf("%c", &temp);
for (int j = 0; j < m - 2; j++) {
scanf("%c", &a[i][j]);
}
scanf("%c\n", &temp);
}
for (int i = 0; i <= m; i++) {
scanf("%c", &temp);
}*/

for (int i = 0; i < n; i++) {
scanf("%c", &temp);
for (int j = 0; j < m; j++) {
scanf("%c", &a[i][j]);
scanf("%c", &G[i][j]);
}
}


//organizing map
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == 'S') {
sh = i;
sv = j;
if (G[i][j] == 'S') {
ih = i;
iv = j;
}
if (a[i][j] == 'C') {
a[i][j] = 'W';

//Marking spots cameras can see with wall
if (G[i][j] == 'C') {
G[i][j] = 'W';
for (int k = 1; k < maxN; k++) {
/*if (d&&(a[i + k][j] == '.'||a[i + k][j] == 'S'))a[i + k][j] = 'W';
if (u&&(a[i - k][j] == '.'||a[i - k][j] == 'S'))a[i - k][j] = 'W';
if (r&&(a[i][j + k] == '.'||a[i][j + k] == 'S'))a[i][j + k] = 'W';
if (l&&(a[i][j - k] == '.'||a[i][j - k] == 'S'))a[i][j - k] = 'W';
if (a[i + k][j] == 'W')d = false;
if (a[i - k][j]== 'W')u = false;
if (a[i][j + k] == 'W')r = false;
if (a[i][j - k] == 'W')l = false;
if (!d&&!u&&!r&&!l)break;*/
if (d && (a[i + k][j] == '.' || a[i + k][j] == 'S'))b[i + k][j] = -1;
if (u && (a[i - k][j] == '.' || a[i - k][j] == 'S'))b[i - k][j] = -1;
if (r && (a[i][j + k] == '.' || a[i][j + k] == 'S'))b[i][j + k] = -1;
if (l && (a[i][j - k] == '.' || a[i][j - k] == 'S'))b[i][j - k] = -1;
if (a[i + k][j] == 'W' || a[i + k][j] == 'C')d = false;
if (a[i - k][j] == 'W' || a[i - k][j] == 'C')u = false;
if (a[i][j + k] == 'W' || a[i][j + k] == 'C')r = false;
if (a[i][j - k] == 'W' || a[i][j - k] == 'C')l = false;
if (d && (G[i + k][j] == '.' || G[i + k][j] == 'S'))dist[i + k][j] = -1;
if (u && (G[i - k][j] == '.' || G[i - k][j] == 'S'))dist[i - k][j] = -1;
if (r && (G[i][j + k] == '.' || G[i][j + k] == 'S'))dist[i][j + k] = -1;
if (l && (G[i][j - k] == '.' || G[i][j - k] == 'S'))dist[i][j - k] = -1;
if (G[i + k][j] == 'W' || G[i + k][j] == 'C')d = false;
if (G[i - k][j] == 'W' || G[i - k][j] == 'C')u = false;
if (G[i][j + k] == 'W' || G[i][j + k] == 'C')r = false;
if (G[i][j - k] == 'W' || G[i][j - k] == 'C')l = false;
if (!d && !u && !r && !l)break;
}
d = u = r = l = true;
}
}
}

move(sh, sv, 0);
move(ih, iv, 0);
//Output
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == '.') {
if (b[i][j] != 0)printf("%d\n", b[i][j]);
if (G[i][j] == '.') {
if (dist[i][j] != 0)printf("%d\n", dist[i][j]);
else printf("%d\n", -1);
}
}
Expand Down

0 comments on commit 82936ca

Please sign in to comment.