- #include<stdio.h>
- int water(int,int);
- int lake[500][500];
- int answer[800000];
- int main(){
- int M,N;
- int a,b;
- int ans;
- int i,j,k=0;
- int m,n,hold;
- int z;
- scanf("%d%d", &M, &N);
- for(a=1;a<=M;a++)
- for(b=1;b<=N;b++){
- scanf("%d", &lake[a][b]);
- }
- for(i=1;i<=M;i++)
- for(j=1;j<=N;j++){
- answer[k]=water(i,j);
- k=k+1;
- }
- for(m=0;m<=k;m++)
- for(n=0;n<=k;n++){
- if(answer[n]<answer[n+1]){
- hold=answer[n];
- answer[n]=answer[n+1];
- answer[n+1]=hold;
- }
- }
- for(z=0;z<=k;z++)
- if(answer[z]>0)
- printf("%d\n",answer[z]);
- return 0;
- }
- int water(int X, int Y){
- int sum=0;
- if(lake[X][Y]==0)
- return 0;
- if(lake[X][Y]!=0){
- sum=sum+1;
- lake[X][Y]=0;
- sum=sum+water(X+1,Y)+water(X,Y-1)+water(X-1,Y)+water(X,Y+1);
- return sum;
- }
- }
Raw Paste