设为首页 加入收藏

TOP

poj2632--模拟
2015-07-20 18:00:15 来源: 作者: 【 】 浏览:1
Tags:poj2632-- 模拟
/** rief poj 2632
 *
 * param date 2014/8/3
 * param state AC
 * 
eturn memory 776k time 16ms
 *
 */

#include 
  
   
#include 
   
     #include 
    
      using namespace std; const int MAXN=101; int Map[MAXN][MAXN]; int A,B; int N,M; int xf[4]={-1,0,1,0}; int yf[4]={0,1,0,-1}; struct Robot { int x; int y; //char dir; int dir; //int num; }; Robot robots[MAXN]; //将方向数字化 int charDir2Int(char cDir) { switch(cDir) { case 'E': return 2; case 'S': return 3; case 'W': return 0; case 'N': return 1; }; } //模拟搜索 bool Forward(int s,int t) { int x,y; int d=robots[s].dir; x=robots[s].x; y=robots[s].y; Map[x][y]=0;//走过为0 for(int i=0;i
     
      A || y<1 || y>B) { cout<
      
       >K; for(int k=0;k
       
        >A>>B; cin>>N>>M; for(int i=1;i<=N;i++) { int x,y; char dir; cin>>x>>y>>dir; robots[i].x=x; robots[i].y=y; robots[i].dir=charDir2Int(dir); //robots[i].num=i; Map[x][y]=i; } bool f=false;//it means that OK for(int j=0;j
        
         >num>>op>>repeat; // if(!f)f=Action(num,op,repeat); } if(!f)cout<
         
          

?

?

?

模拟算法:根据题目所述移动步骤逐步进行,利用数组array[i][j]代表(i,j)位置处的robot编号,没有则为0.

利用robot结构体记录下每个机器人当前的位置和方向。

对于'F'指令,需判断前进是否出界和前进的位置是否已有机器人。

对于'L'和'R'转向指令,只需修改机器人的方向值,注意同一方向转四次等于没转。

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 1501 Zipper (dfs+记忆化搜.. 下一篇hdu 4910 Problem about GCD(数论)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: