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 liangcheng at 2009-11-22 21:40:34 on Problem 1573
#include <stdlib.h>
#include<stdio.h>
#include<string.h>
char gird[15][15];
int  flag,gnum[15][15],cir[15][15];
int Dfs(int x,int y,int row,int col);
/*
 * pku 1573 
 */
int main(int argc, char** argv) {
    int i,j,k,t,row,col,start,temp;
    freopen("test.in","r",stdin);
    while(scanf("%d%d%d",&row,&col,&start)!=EOF){
        if(row==0&&col==0&&start==0)break;
        memset(gnum,0,sizeof(gnum));
        for(i=0;i<row;i++){scanf("%s",gird[i]);}
        flag=0;
        temp=Dfs(0,start-1,row,col);
        if(temp==0){
            printf("%d step(s) to exit\n",flag);
        }
        else  printf("%d step(s) before a loop of %d step(s)\n",temp,flag-temp);
//        printf("%d\n",temp);
   
    }
    return (EXIT_SUCCESS);
}
int  Dfs(int x,int y,int row,int col){
    int i,j;

    if(gnum[x][y]) return  gnum[x][y];
    else if(x<0||x>row||y<0||y>col) return 0;
    else{
       gnum[x][y]=flag;
       switch(gird[x][y]){
           case 'N':   flag++;x--; return Dfs(x,y,row,col);
           case 'S':   flag++;x++; return Dfs(x,y,row,col);
           case 'W':   flag++;y--; return Dfs(x,y,row,col);
           case 'E':   flag++;y++; return Dfs(x,y,row,col);
        }
    } 
    
}

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