-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
102 lines (79 loc) · 1.7 KB
/
main.cpp
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <stack>
#include <utility>
#include <map>
using namespace std;
const int MOVES = 510 * 100 + 205; // Number of ant's moves
map <pair <int, int>, int> theMap;
#define mp make_pair
#define fi first
#define se second
int main(){
int x = 0, y = 0;
char dir = 'N';
int r = 0, last = 0;
/*
// Change the initial map to chess board 100x100
for(int i = -50; i < 50; i++){
if(last == r){
r ^= 1;
last = r;
}
for(int j = -50; j < 50; j++){
theMap[mp(i, j)] = r;
r ^= 1;
}
}
*/
int maxX = 0, minX = 0, maxY = 0, minY = 0;
for(int i = 0; i < MOVES; i++){
if(theMap[mp(x, y)] == 0){
// direction counterclockwise
if(dir == 'N') dir = 'W';
else if(dir == 'W') dir = 'S';
else if(dir == 'S') dir = 'E';
else if(dir == 'E') dir = 'N';
}
else{
// direction clockwise
if(dir == 'N') dir = 'E';
else if(dir == 'W') dir = 'N';
else if(dir == 'S') dir = 'W';
else if(dir == 'E') dir = 'S';
}
theMap[mp(x, y)] = !theMap[mp(x, y)];
if(dir == 'N') y++;
else if(dir == 'W') x--;
else if(dir == 'S') y--;
else if(dir == 'E') x++;
maxX = max(maxX, x);
minX = min(minX, x);
maxY = max(maxY, y);
minY = min(minY, y);
}
/* Only for debugging purposes
cerr << maxX << " - " << minX << endl;
cerr << maxX << " - " << minY << endl;
*/
int n = max(abs(maxX), abs(minX));
n = max(n, abs(minY));
n = max(n, abs(maxY));
printf("%d\n", n);
//cerr << n;
for(int i = n ; i >= -n; i--){
for(int j = -n; j < n; j++){
if(theMap[mp(j, i)] == 0){
printf("0 ");
}
else{
printf("1 ");
}
}
printf("\n");
}
return 0;
}