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

这道题不是用广度搜索吗?高人来看一下,严重超时

Posted by hahaxiao at 2005-09-16 09:16:04 on Problem 1088
#include <stdio.h>
int r,c;

struct abc{
    int i,j;
    int step;
}que[10000000],tem;    
int search(int m,int n,int a[101][101]){
    int front,rear;
    int i,j;
    int max=0;
    front=0; rear=0;
    que[rear].i=m; que[rear].j=n; que[rear].step=1;
    rear=(rear+1)%10000000;  
    while(front!=rear) {
        tem.i=que[front].i;
        tem.j=que[front].j;
        tem.step=que[front].step;
        if(max<tem.step) max=tem.step;
        front=(front+1)%10000000;
        if(a[tem.i-1][tem.j]<a[tem.i][tem.j] && tem.i>1) {
            que[rear].i=tem.i-1;
            que[rear].j=tem.j;
            que[rear].step=tem.step+1;
            rear=(rear+1)%10000000;
        }
        if(a[tem.i+1][tem.j]<a[tem.i][tem.j]&& tem.i<r) {
            que[rear].i=tem.i+1;    
            que[rear].j=tem.j;
            que[rear].step=tem.step+1;
            rear=(rear+1)%10000000;
        }
        if(a[tem.i][tem.j-1]<a[tem.i][tem.j] && tem.j>1) {
            que[rear].i=tem.i;
            que[rear].j=tem.j-1;
            que[rear].step=tem.step+1;
            rear=(rear+1)%10000000;
        }
        if(a[tem.i][tem.j+1]<a[tem.i][tem.j] && tem.j<c) {
            que[rear].i=tem.i;
            que[rear].j=tem.j+1;
            que[rear].step=tem.step+1;   
            rear=(rear+1)%10000000;
        }
    }
    return max;
}                 
        
          
    
int main() {
    int i,j;
    int temp;
    int a[101][101];
    int max;
    while(scanf("%d%d",&r,&c)!=EOF) {
        for(i=1;i<=r;i++){
            for(j=1;j<=c;j++){
                scanf("%d",&a[i][j]);
            }    
        }   
        max=0;     
        for(i=1;i<=r;i++){
            for(j=1;j<=c;j++){
                temp=search(i,j,a);
                if(max<temp) {
                    max=temp;
                }    
            }
        }
        printf("%d\n",max);
    }
    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