PKU 1573 模拟

很简单的模拟题

代码如下
/**********************
Author: WHU_Victordu
Created Time: 2007-12-28
File Name: pku1573.cpp
  Description: 
   **************************/
#include <stdio.h>
#include <string.h>

char map[11][11];
int used[11][11];

int main()
{
    int col,row,stpos,i,j,posx,posy,k,lcnt,scnt;
    char dir;
    while(scanf("%d%d%d",&row,&col,&stpos)!=EOF)
    {
      if(row==0&&col==0&&stpos==0) break;
     
      for(i=1;i<=row;i++)
      {
        scanf("%s",map[i]);
      }
        
      memset(used,0,sizeof(used));
      used[1][stpos-1]=1;
      posx=1;posy=stpos-1;
      dir=map[posx][posy];
     
      k=2;scnt=1;lcnt=0;
     
      while(posx>=1&&posx<=row&&posy>=0&&posy<col)
      {
        if(dir=='N') posx--;
        if(dir=='S') posx++;
        if(dir=='E') posy++;
        if(dir=='W') posy--;
        if(used[posx][posy]) {lcnt=k-used[posx][posy];scnt-=lcnt;break;}
        else
        {
        used[posx][posy]=k;
        k++;
        dir=map[posx][posy];
        scnt++;
        }      
      }
     
      if(lcnt)
      printf("%d step(s) before a loop of %d step(s)\n",scnt,lcnt);
      else
      printf("%d step(s) to exit\n",scnt-1);
   
    }
}

posted on 2007-12-28 16:12 Victordu 阅读(843) 评论(1)  编辑 收藏 引用

评论

# re: PKU 1573 模拟 2010-03-21 20:33 发生的范德萨

多点注释....  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

<2010年3月>
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

统计

常用链接

留言簿(5)

随笔档案(46)

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜