Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# muzikasi

By: a guest on Feb 21st, 2012  |  syntax: C++  |  size: 1.04 KB  |  views: 5  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. #include <cstdio>
2. #include <queue>
3. using namespace std;
4.
5. int n,m;
6. long long zbr;
7. char a[1007][1007];
8. queue <int> qx;
9. queue <int> qy;
10. int bfs ()
11. {
12.     int x,y;
13.     while (!qx.empty()){
14.           x=qx.front(); y=qy.front();
15.           a[x][y]='0';
16.           if (a[x-1][y]=='.') { qx.push (x-1); qy.push (y); a[x-1][y]='0';}
17.           if (a[x][y+1]=='.') { qx.push (x); qy.push (y+1); a[x][y+1]='0';}
18.           if (a[x+1][y]=='.') { qx.push (x+1); qy.push (y); a[x+1][y]='0';}
19.           if (a[x][y-1]=='.') { qx.push (x); qy.push (y-1); a[x][y-1]='0';}
20.           zbr++;
21.           qx.pop();qy.pop();
22.     }
23. }
24.
25. int main ()
26. {
27.     scanf ("%d%d",&n,&m);
28.     for (int i=0;i<n;i++){
29.         scanf ("%s",a[i]);
30.     }
31.     int x,y;
32.     long long max=0;
33.     for (int i=0;i<n;i++){
34.         for (int j=0;j<m;j++){
35.             if (a[i][j]=='.'){
36.                 qx.push (i); qy.push (j);
37.                 bfs();
38.                 if (zbr>max) max=zbr;
39.                 zbr=0;
40.             }
41.         }
42.     }
43.     printf ("%I64lld",max);
44. }
clone this paste RAW Paste Data
Top