走格子收获
来源:互联网 发布:思创医惠 人工智能 编辑:程序博客网 时间:2024/04/29 18:07
eg:poj2632 code:#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int a,b;int queue[101][101];int xx[4]= {-1,0,1,0}; //!!!!!!!注意这里方向的顺序必须和0、1、2、3保持一致!!!!WA了好多遍都不知道哪错了int yy[4]= {0,1,0,-1};struct spot{ int x,y,d;} robot[101];bool forward(int s,int t){ int x=robot[s].x; int y=robot[s].y; int d=robot[s].d; queue[x][y]=0; for(int i=0; i<t; i++) { x+=xx[d]; y+=yy[d]; if(queue[x][y]) { cout<<"Robot "<<s<<" crashes into robot "<<queue[x][y]<<endl; return true; } if(x<1||x>a||y>b||y<1) { cout<<"Robot "<<s<<" crashes into the wall"<<endl; return true; } } robot[s].x=x; robot[s].y=y; queue[x][y]=s; return false;}bool action(int s,char dir,int t){ switch (dir) { case 'F': return forward(s,t); case 'L': robot[s].d=(robot[s].d-t%4+4)%4; //是编号始终为0、1、2、3 对于绕桌子一圈编号问题一样 break; case 'R': robot[s].d=(robot[s].d+t%4)%4; break; } return false;}int main(){ int k; int n,m,t,s; int xi,yi; char dir; cin>>k; bool f=false; while(k--) { memset(queue,0,sizeof(queue)); memset(robot,0,sizeof(struct spot)*101); cin>>a>>b>>n>>m; for(int i=1; i<=n; i++) { cin>>xi>>yi>>dir; queue[xi][yi]=i; //这里注意,通过编号找位置,通过位置找编号 robot[i].x=xi; robot[i].y=yi; switch(dir) //可以用0、1、2、3来表示方向 { N : 1 case 'N': W:0 + E :2 robot[i].d=1; S : 3 break; case 'S': robot[i].d=3; break; case 'W': robot[i].d=0; break; case 'E': robot[i].d=2; break; } } f=false; for(int i=0; i<m; i++) { cin>>s>>dir>>t; if(!f) f=action(s,dir,t); } if(!f) cout<<"OK"<<endl; }}
0 0
- 走格子收获
- 走格子
- 走格子
- 走格子
- 走格子
- 走格子
- 走格子/走棋盘问题
- 8.2-走格子
- 走格子经典题
- 51nod1344 走格子
- 走格子问题
- 华为oj--走格子
- 动态规划---走格子
- 51Nod1344 走格子
- 走格子问题
- 51 nod1344走格子
- t -马走格子
- 走格子问题
- PC端(基于Linux系统)通过串并网线口连接ARM开发板,烧写Bootloader并启用Bootp和Tftp等服务刷写Linux系统。
- PL/SQL developer链接远程数据库
- 是输入字符矩阵时
- Varnish 4 笔记
- NSMutableAttributedString
- 走格子收获
- php面向对象编程
- 第3周-项目4-百钱买百鸡
- 自己写的一个数组与list转化工具,请大神指正问题
- memset结构体初始化
- JAVA对象Bean输出(toString)
- 移动平台对 meta 标签的定义
- JVM垃圾回收器常用参数介绍
- groovy学习资料收藏