1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
// Recursive fill
#include<iostream>
#include<array>
#include<cstdio>
const int N = 200; // maximum ok value, 67 for VS 2012, 178 for GCC 4.8
using namespace std;
void Fill( array<array<bool,N>,N> &arr, int i, int j){
arr[i][j]=1;
if(i+1>=0 && i+1<N && arr[i+1][j] == 0) Fill(arr, i+1, j);
if(j+1>=0 && j+1<N && arr[i][j+1] == 0) Fill(arr, i, j+1);
if(i-1>=0 && i-1<N && arr[i-1][j] == 0) Fill(arr, i-1, j);
if(j-1>=0 && j-1<N && arr[i][j-1] == 0) Fill(arr, i, j-1);
}
int main(){
//freopen("grun.cpp","w",stdout);
array<array<bool,N>,N> arr;
for(auto &R:arr) for(auto &C:R) {
C=0; //sel all zero
}
int x=0, y=0;
Fill(arr, x, y); // fill starts from (0,0)
/* //print
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
cout << arr[i][j] << "";
}
cout << endl;
}
*/
return 0;
}
|