Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define mx 510
- char grid[mx][mx];
- char grid2[mx][mx];
- int count = 0;
- int ara[] = { -1, 0, 1 };
- int n, m;
- int len;
- void init()
- {
- int i, j;
- for (i = 0; i < mx; i++)
- for (j = 0; j < mx; j++)
- grid[i][j] = grid2[i][j] = '\0';
- }
- int checkValidity(int x, int y)
- {
- if (x < 0)
- return 0;
- if (x >= m)
- return 0;
- if (y < 0)
- return 0;
- if (y >= len)
- return 0;
- return 1;
- }
- void copyGrid()
- {
- count = 0;
- int i, j;
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < strlen(grid[i]) ; j++)
- {
- grid2[i][j] = grid[i][j];
- }
- grid2[i][j] = '\0';
- }
- }
- void fill(int x, int y)
- {
- int i, j;
- grid2[x][y] = 'L';
- count++;
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j < 3; j++)
- {
- if (checkValidity(x + ara[i], y + ara[j]) && grid2[x + ara[i]][y + ara[j]] == 'W')
- {
- fill(x + ara[i], y + ara[j]);
- }
- }
- }
- }
- int main()
- {
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- int t, T, i, j, k;
- int x, y;
- int u, v;
- char st[100];
- int fcheck = 0;
- scanf("%d", &T);
- getchar();
- getchar();
- for (t = 1; t <= T; t++)
- {
- i = 0;
- n = 0;
- m = 0;
- if (t != 1)
- printf("\n");
- init();
- while ( gets(grid[i]) )
- {
- if (grid[i][0] == '\0')
- break;
- if (grid[i][0] != 'W' && grid[i][0] != 'L' && 0 == n)
- n = i;
- i++;
- }
- m = i;
- len = strlen(grid[0]);
- for (k = n; k < m; k++)
- {
- x = y = i = 0;
- while (grid[k][i] != ' ')
- x = x * 10 + (grid[k][i++] - '0');
- i++;
- while (grid[k][i] != '\0')
- y = y * 10 + (grid[k][i++] - '0');
- copyGrid();
- fill(x - 1, y - 1);
- printf("%d\n", count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment