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

我的ac了,但好象有不足之处,自己发现不了,高手帮一下,修改一下,运行时间较长。

Posted by dellenge at 2007-05-20 11:03:30 on Problem 1088
#include"stdio.h"
int main()
{
    int i, j ,k, m, n, max;
    int a[101][101];
     int b[101][101]={0};
     scanf("%d%d",&n,&m)  ;
        for(i =0; i<n; i++)
        for(j = 0; j<m ;j++)
        scanf("%d",&a[i][j]);
       for(k=0;k<n;k++)
       {
        for(i=0; i<n; i++)              //从上向下选
        for(j=0; j<m; j++)
        {
            if(i-1>=0)
                if(a[i-1][j]>a[i][j])
                  if(b[i][j]>=b[i-1][j])
                       b[i-1][j]=b[i][j]+1;
            if(j-1>=0)
                if(a[i][j-1]>a[i][j])
                     if(b[i][j]>=b[i][j-1])
                       b[i][j-1]=b[i][j]+1;
            if(i+1<n)
                if(a[i+1][j]>a[i][j])
                     if(b[i][j]>=b[i+1][j])
                       b[i+1][j]=b[i][j]+1;
            if(j+1<m)
                if(a[i][j+1]>a[i][j])
                      if(b[i][j]>=b[i][j+1])
                       b[i][j+1]=b[i][j]+1;
        }
        for(i=n-1; i>=0; i--)            //从下向上选
        for(j=m-1; j>=0; j--)
        {
            if(i-1>=0)
                if(a[i-1][j]>a[i][j])
                  if(b[i][j]>=b[i-1][j])
                       b[i-1][j]=b[i][j]+1;
            if(j-1>=0)
                if(a[i][j-1]>a[i][j])
                     if(b[i][j]>=b[i][j-1])
                       b[i][j-1]=b[i][j]+1;
            if(i+1<n)
                if(a[i+1][j]>a[i][j])
                     if(b[i][j]>=b[i+1][j])
                       b[i+1][j]=b[i][j]+1;
            if(j+1<m)
                if(a[i][j+1]>a[i][j])
                      if(b[i][j]>=b[i][j+1])
                       b[i][j+1]=b[i][j]+1;
        }
        }
        max=b[0][0] ;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            if(max<b[i][j])
            max=b[i][j];
        }
        printf("%d\n",max+1) ;
    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