Created
July 6, 2015 09:33
-
-
Save rogerioagjr/0a4aaac945a8067d801a to your computer and use it in GitHub Desktop.
Colorindo
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 MAXN 220 | |
bool tab[MAXN][MAXN]; | |
int n, m, x, y, k, qtd; | |
// DFS | |
void dfs(int v, int h){ | |
// se não puder pintar o quadrado, retorno | |
if(v<1 or v>n or h<1 or h>m or tab[v][h]) return; | |
// caso contrário, o pinto | |
tab[v][h]=true; | |
qtd++; | |
// e percorro todos os seus vizinhos | |
for(int i=v-1; i<=v+1; i++) | |
for(int j=h-1; j<=h+1; j++) | |
dfs(i, j); // chamando a DFS para cada um deles | |
} | |
int main(){ | |
// leio os valores de n, m, x, y e k | |
scanf("%d %d %d %d %d", &n, &m, &x, &y, &k); | |
// para cada quadrado preto | |
for(int i=1; i<=k; i++){ | |
// leio suas coordenadas | |
int a, b; | |
scanf("%d %d", &a, &b); | |
// e o marco na matriz | |
tab[a][b]=true; | |
} | |
// chamo a DFS no quadrado inicial | |
dfs(x, y); | |
// e imprimo o valor de qtd | |
printf("%d\n", qtd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment