Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1088感觉这两个代码完全没区别啊。为什么一个AC,一个Runtime Error?求解

Posted by HCA1101 at 2012-02-08 13:12:42
Runtime Error代码如下:
#include"stdio.h"
int a[102][102],b[102][102]={0};
int shou(int i,int j)
{int max=0,t;
if(a[i][j-1]>a[i][j])t=0;
else 
{if(b[i][j-1]==0) t=shou(i,j-1);
else t=b[i][j-1];
}
max=t>max?t:max;
if(a[i][j+1]>a[i][j])t=0;
else 
{if(b[i][j+1]==0) t=shou(i,j+1);
else t=b[i][j+1];
}
max=t>max?t:max;
if(a[i+1][j]>a[i][j])t=0;
else 
{if(b[i+1][j]==0) t=shou(i+1,j);
else t=b[i+1][j];
}
max=t>max?t:max;
if(a[i-1][j]>a[i][j])t=0;
else 
{if(b[i-1][j]==0) t=shou(i-1,j);
else t=b[i-1][j];
}
max=t>max?t:max;
b[i][j]=max+1;
return max+1;
}
int main()
{int m,n,i,j,p=0,maxn=0;
scanf("%d %d",&m,&n);
for(i=0;i<=m+1;i++)
{a[i][0]=10001;
a[i][n+1]=10001;
}
for(j=0;j<=n+1;j++)
{a[0][j]=10001;
a[m+1][j]=10001;
}
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{if(b[i][j]==0)p=shou(i,j);
maxn=p>maxn?p:maxn;
}
printf("%d\n",maxn);
return 0;
}
AC代码如下:
#include "stdio.h"

int a[102][102];    

int b[102][102]={0};   

int shou(int i,int j)

{

       int max=0,t; 

       if (a[i][j-1]>=a[i][j]) t=0; 

       else     
       {

              if (b[i][j-1]==0)  

              { 

                     t=shou(i,j-1);

              }

              else t=b[i][j-1]; 

       }
       max=max>t?max:t;       

       if (a[i][j+1]>=a[i][j]) t=0;

       else

       {

              if (b[i][j+1]==0) 

              {            

                     t=shou(i,j+1);

              }

              else t=b[i][j+1];

       }

       max=max>t?max:t;

       if (a[i-1][j]>=a[i][j]) t=0;

       else

       {

              if (b[i-1][j]==0) 

              {            

                     t=shou(i-1,j);

              }

              else t=b[i-1][j];

       }

       max=max>t?max:t;

       if (a[i+1][j]>=a[i][j]) t=0;

       else

       {

              if (b[i+1][j]==0) 

              {

                     t=shou(i+1,j);

              }

              else t=b[i+1][j];

       }

       max=max>t?max:t;


       b[i][j]=max+1;

       return max+1;

}

int main ()

{

       int r,c; 

       int i,j;

       int maxx=0,p;

       scanf ("%d %d",&r,&c);



       for (i=0;i<=r+1;i++) 

       {

              a[i][0]=10001;

              a[i][c+1]=10001;

       }

       for (j=0;j<=c+1;j++)

       {

              a[0][j]=10001;

              a[r+1][j]=10001;

       }


       for (i=1;i<=r;i++)

       {

              for (j=1;j<=c;j++)

              {

                     scanf ("%d",&a[i][j]);

              }

       }
       for (i=1;i<=r;i++)

              for (j=1;j<=c;j++)

                     if(b[i][j]==0) 

                     {

                            p=shou(i,j);

                            if (p>maxx) maxx=p; 

                     }


       printf ("%d\n",maxx);
      return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator