poj2632
来源:互联网 发布:建筑优化 编辑:程序博客网 时间:2024/05/22 03:15
一开始不小心把测试也写了进去,然后WA了好几遍。。。。。。
模拟题,题目比较难懂,而且坐标是倒过来的,输入是先输入列的长度,然后只要某一个机器人先撞到墙或其他机器人就可以直接忽略后面直接输出了
只要注意这几个点就没什么问题了
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <stack>
using namespace std;
//E 0 N 1 W 2 S 3
int dre[4][2]={0,1,1,0,0,-1,-1,0};
int vis[103][105];
map<char,int>w;
void init()
{
w['E']=0;
w['N']=1;
w['W']=2;
w['S']=3;
}
struct robot
{
int x,y;
int d;
}r[105];
int main()
{
int t,n,m,row,col;
cin>>t;
init();
while(t--)
{
cin>>col>>row;
cin>>n>>m;
char s;
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
{
cin>>r[i].y>>r[i].x>>s;
r[i].d=w[s];
vis[r[i].x][r[i].y]=i;
}
int f=0,ff=0;
int a,b;
while(m--)
{
cin>>a>>s>>b;
if(f==0)
{
while(b--)
{
if(s=='L')r[a].d=(r[a].d+1)%4;
if(s=='R')r[a].d=(r[a].d+3)%4;
if(s=='F')
{
int xi=r[a].x+dre[r[a].d][0];
int yi=r[a].y+dre[r[a].d][1];
if(xi<=0||xi>row||yi<=0||yi>col)
{
f=a;
}
else if(vis[xi][yi])
{
f=a;
ff=vis[xi][yi];
}
else
{
vis[r[a].x][r[a].y]=0;
r[a].x=xi;
r[a].y=yi;
vis[xi][yi]=a;
}
}
}
}
}
//for(int i=1;i<=n;i++)
// cout<<r[i].x<<' '<<r[i].y<<' '<<r[i].d<<endl;
if(f>0&&ff==0)
{
cout<<"Robot "<<f<<" crashes into the wall"<<endl;
}
else if(f&&ff)
{
cout<<"Robot "<<f<<" crashes into robot "<<ff<<endl;
}
else if(!f)cout<<"OK"<<endl;
}
return 0;
}
- POJ2632
- POJ2632
- poj2632
- POJ2632
- POJ2632
- poj2632
- poj2632
- POJ2632
- poj2632
- poj2632
- poj2632--模拟
- poj2632(模拟)
- Crashing Robots POJ2632
- poj2632 Crashing Robots
- POJ2632--Crashing Robots--模拟
- POJ2632 Crashing Robots
- poj2632--Crashing Robots
- POJ2632 Crashing Robots
- 软件工程导论第一章第七题
- (1.4.10)SXF笔试题汇总
- git学习笔记
- javascript 学习笔记 (二)
- floyd判圈算法
- poj2632
- Java并发知识点总结(上)
- 华为oj-名字漂亮度
- 作业调度算法
- uva 11383 - Golden Tiger Claw(完美匹配)
- 黑马程序员—java技术blog—第四篇 IO流中其他流概述总结
- 高斯随机数发生程序
- 分析OpenCV图像输入输出基本框架
- Linux复习笔记(一) -- Bash的基本操作