Created
July 6, 2015 09:34
-
-
Save rogerioagjr/a06739cb4239be366cdb to your computer and use it in GitHub Desktop.
Colorindo - Roger Benet
This file contains 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 <cstdio> | |
#define MAX 210 | |
int matrix[MAX][MAX]; | |
int n,m,k,x,y; | |
void dfs(int i, int j){ | |
if(i >= 1 && i <= n && j >= 1 && j <= m){ | |
if(matrix[i][j] == 0)matrix[i][j] = 1; | |
if(matrix[i-1][j-1] == 0){ | |
matrix[i-1][j-1] = 1; | |
dfs(i-1,j-1); | |
} | |
if(matrix[i-1][j] == 0){ | |
matrix[i-1][j] = 1; | |
dfs(i-1,j); | |
} | |
if(matrix[i-1][j+1] == 0){ | |
matrix[i-1][j+1] = 1; | |
dfs(i-1,j+1); | |
} | |
if(matrix[i][j-1] == 0){ | |
matrix[i][j-1] = 1; | |
dfs(i,j-1); | |
} | |
if(matrix[i][j+1] == 0){ | |
matrix[i][j+1] = 1; | |
dfs(i,j+1); | |
} | |
if(matrix[i+1][j-1] == 0){ | |
matrix[i+1][j-1] = 1; | |
dfs(i+1,j-1); | |
} | |
if(matrix[i+1][j] == 0){ | |
matrix[i+1][j] = 1; | |
dfs(i+1,j); | |
} | |
if(matrix[i+1][j+1] == 0){ | |
matrix[i+1][j+1] = 1; | |
dfs(i+1,j+1); | |
} | |
} | |
} | |
int main(){ | |
scanf("%d %d %d %d %d", &n ,&m, &x, &y, &k); | |
while(k--){ | |
int a,b; | |
scanf("%d %d", &a, &b); | |
matrix[a][b] = -1; | |
} | |
dfs(x,y); | |
k = 0; | |
for(int i = 1; i <= n; i++){ | |
for(int j = 1; j <= m; j++){ | |
if(matrix[i][j] == 1)k++; | |
} | |
} | |
printf("%d\n",k); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment