| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:救命啊!!!!!!!!!!In Reply To:Re:救命啊!!!!!!!!!! Posted by:LiWang112358 at 2008-11-12 19:57:14 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int r,c,t,map[100][100],map1[100][100];
int D[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int rear,stack[100][2],stacknext[100][2];
int step,contnow,contnext;
int bfs(int x,int y){
map1[x][y]=1;
stack[0][0]=x;
stack[0][1]=y;
contnow=1;
step=0;
while(contnow!=0){
step++;
rear=0;
contnext=0;
for(int i=0;i<contnow;i++)
for(int j=0;j<4;j++){
int xx=stack[i][0]+D[j][0],yy=stack[i][1]+D[j][1];
if(xx>=0&&xx<r&&yy>=0&&yy<c
&&map[xx][yy]<map[stack[i][0]][stack[i][1]]){
stacknext[rear][0]=xx;
stacknext[rear++][1]=yy;
map1[xx][yy]=1;
contnext++;
}
}
contnow=contnext;
for(int i=0;i<contnow;i++){
stack[i][0]=stacknext[i][0];
stack[i][1]=stacknext[i][1];
}
}
return step;
}
int main(){
while(scanf("%d%d",&r,&c)!= EOF){
int max=0;
memset(map1,0,sizeof(map1));
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
scanf("%d",&map[i][j]);
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
if(map1[i][j]!=1){
t=bfs(i,j);
if(t>max) max=t;
}
printf("%d\n",max);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator