Last active
May 25, 2016 13:11
-
-
Save macrat/60c38cd848e17d15b86163482aa9836a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdbool.h> | |
| #include <stdint.h> | |
| #include <stdio.h> | |
| struct { | |
| int_fast32_t x, y; | |
| } typedef Position; | |
| int main(){ | |
| const Position cands[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; | |
| uint_fast32_t w, h, x, y, stack_itr, count; | |
| uint_fast8_t c, i; | |
| Position p; | |
| while(scanf("%lu %lu\n", &w, &h) && w){ | |
| bool tile[h][w]; | |
| Position stack_data[h*w]; | |
| stack_itr = 1; | |
| count = 0; | |
| for(y=0; y<h; ++y){ | |
| for(x=0; x<w; ++x){ | |
| c = fgetc(stdin); | |
| tile[y][x] = c == '.'; | |
| if(c == '@'){ | |
| stack_data[0].x = x; | |
| stack_data[0].y = y; | |
| } | |
| } | |
| fgetc(stdin); | |
| } | |
| while(stack_itr){ | |
| count++; | |
| stack_itr--; | |
| p = stack_data[stack_itr]; | |
| for(i=0; i<4; ++i){ | |
| x = p.x + cands[i].x; | |
| y = p.y + cands[i].y; | |
| if(x < w && y < h && tile[y][x]){ | |
| tile[y][x] = false; | |
| stack_data[stack_itr].x = x; | |
| stack_data[stack_itr].y = y; | |
| stack_itr++; | |
| } | |
| } | |
| } | |
| printf("%lu\n", count); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment