// yukicoder: No.331 CodeRunnerでやれ // bal4u 2019.8.15 #include #include #if 0 int H = 19, W = 17; char map[25][25] = { "#################", "#>..............#", "###############.#", "#.............#.#", "#.###########.#.#", "#.#.........#.#.#", "#.#.#######.#.#.#", "#.#.#.....#.#.#.#", "#.#.#.###.#.#.#.#", "#.#.#.#...#.#.#.#", "#.#.#.#.###.#.#.#", "#.#.#.#.....#.#.#", "#.#.#.#######.#.#", "#.#.#.........#.#", "#.#.###########.#", "#.#.............#", "#.###############", "#...............#", "###############.#", }; int H = 19, W = 19; char map[25][25] = { "###################", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#^#.#.#", "#####.#############" }; int H = 20, W = 20; char map[25][25] = { "####################", "#..........#.#...#.#", "##..#..##.#....#...#", "#.##.#...#.#.#..##.#", "#......#.#..#.#..#..", "#.#.#.#.#..#...#..##", "#..#.....#...#..#.##", "#.#..#.#..#.#.#....#", "#..##...#.....#.##.#", "#.#.###..####.#..#.#", "#.#....#.......#..##", "#..#.#..#.#.###..#.#", "#.#..#.#..##...##..#", "#..#..#..#...#...#.#", "#.#..#.#...#..##...#", "#.##.....#..##...#.#", "#...#.#.#.#...#.#..#", "##.#>#.#.#..##...#.#", "#....#.....#...##..#", "####################" }; int H = 19, W = 19; char map[25][25] = { "###################", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.................#", "..#.#.#.#.#.#.#<#.#", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.................#", "###################" }; int H = 19, W = 17; char map[25][25] = { "#################", "#>..............#", "###############.#", "#.............#.#", "#.###########.#.#", "#.#.........#.#.#", "#.#.#######.#.#.#", "#.#.#.....#.#.#.#", "#.#.#.###.#.#.#.#", "#.#.#.#...#.#.#.#", "#.#.#.#.###.#.#.#", "#.#.#.#.....#.#.#", "#.#.#.#######.#.#", "#.#.#.........#.#", "#.#.###########.#", "#.#.............#", "#.###############", "#...............#", "###############.#" }; #endif #define TEST 0 int H = 19, W = 19; char map[25][25] = { "###################", "#.................#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#.#.#.#", "#.#.#.#.#.#.#^#.#.#", "#####.#############" }; int r, c, dir, step; int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; void init() { #if TEST for (r = 0; r < H; r++) for (c = 0; c < W; c++) { if (map[r][c] == '^') { dir = 0; return; } if (map[r][c] == 'v') { dir = 2; return; } if (map[r][c] == '<') { dir = 3; return; } if (map[r][c] == '>') { dir = 1; return; } } printf("Panic!!! no initial (r,c)\n"); exit(0); #endif } void move(char *s, char ch) { #if TEST int rr, cc; *(s+1) = 0; if (ch == 'L') { if (--dir < 0) dir += 4; rr = r + mv[dir][0], cc = c + mv[dir][1]; *s = (map[rr][cc] != '#')? '1': '0'; } else if (ch == 'R') { if (++dir == 4) dir -= 4; rr = r + mv[dir][0], cc = c + mv[dir][1]; *s = (map[rr][cc] != '#')? '1': '0'; } else if (ch == 'F') { rr = r + mv[dir][0], cc = c + mv[dir][1]; if (rr < 0 || rr >= H || cc < 0 || cc >= W) *s = 'M'; else { if (map[rr][cc] != '#') r = rr, c = cc, *s = '1'; else *s = '0'; } } else if (ch == 'B'); else *s = (map[r][c] != '#')? '1': '0'; printf("ch=%c, (%d,%d) dir=%d\n", ch, r,c,dir); if (++step > 5000) { printf("Time over\n"); exit(0); } #endif } int action(char ch) { char s[20]; int d; while (1) { #if TEST move(s, ch); #else if (ch) { putchar(ch), putchar('\n'); fflush(stdout); } scanf("%s", s); #endif if (*s == 'M') { #if TEST printf("OK steps=%d\n", step); #endif exit(0); } if ((d = atoi(s)) < 20151224) break; ch = 'F'; } return d; } int main() { int d; char a; init(); d = action(0); while (d) d = action('F'); d = action('L'); while (d) d = action('F'); d = action('L'); while (1) { if (d == 0) d = action('R'); while (d == 0) d = action('L'); while (d = action('F')) { d = action('R'); if (d == 0) d = action('L'); } } return 0; }