xfstart07
Get busy living or get busy dying
#include < cstdio >
#include
< cstring >
using   namespace  std;

int  N,M;
int  Ans;
int  x[ 2510 ][ 2510 ];
int  m[ 2510 ][ 2510 ];
int  f[ 2510 ][ 2510 ];
void  init()
{
    
for ( int  i = 1 ;i <= N; ++ i)
        
for ( int  j = 1 ;j <= M; ++ j)
            scanf(
" %d " , & m[i][j]);
}
int  countx( int  x, int  y)
{
    
int  l = 0 ;
    
while (x >= 1 && m[x][y] == 0 ){ l ++ ; x -- ; }
    
return  l;
}
int  county( int  x, int  y)
{
    
int  l = 0 ;
    
while (y >= 1 && m[x][y] == 0 ) { l ++ ; y -- ; }
    
return  l;    
}
int  countyy( int  x, int  y)
{
    
int  l = 0 ;
    
while (y <= M && m[x][y] == 0 ) { l ++ ; y ++ ; }
    
return  l;
}
int  min( int  x, int  y, int  z)
{
    
if (x > y) x = y;  if (x > z) x = z;
    
return  x;
}
void  solve()
{
    memset(f,
0 , sizeof (f));
    Ans
= 0 ;
    
for ( int  i = 1 ;i <= N; ++ i)
        
for ( int  j = 1 ;j <= M; ++ j)
            
if (m[i][j] == 1 ){
                
int  x = countx(i - 1 ,j),y = county(i,j - 1 );
                f[i][j]
= min(x,y,f[i - 1 ][j - 1 ]) + 1 ;
                
if (f[i][j] > Ans) Ans = f[i][j];
            }
    memset(f,
0 , sizeof (f));
    
for ( int  i = 1 ;i <= N; ++ i)
        
for ( int  j = M;j >= 1 ; -- j)
            
if (m[i][j]){
                
int  x = countx(i - 1 ,j),y = countyy(i,j + 1 );
                f[i][j]
= min(x,y,f[i - 1 ][j + 1 ]) + 1 ;
                
if (f[i][j] > Ans) Ans = f[i][j];
            }
}
int  main()
{
    
while (scanf( " %d%d " , & N, & M) != EOF){
        init();
        solve();
        printf(
" %d\n " ,Ans);
    }
    
return   0 ;
}




posted on 2009-08-15 11:15 xfstart07 阅读(346) 评论(0)  编辑 收藏 引用 所属分类: 代码库

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理