In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occupy a circular floor space with a diameter of 1 meter. Assume there are N robots, numbered from 1 through N. You will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. Instructions are processed in the order they come. No two robots move simultaneously; a robot always completes its move before the next one starts moving.
A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.

Input

The first line of input is K, the number of test cases. Each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the EW-direction, and B in the NS-direction.
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively. 
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position. 
 
Figure 1: The starting positions of the robots in the sample warehouse
Finally there are M lines, giving the instructions in sequential order. 
An instruction has the following format: 
< robot #> < action> < repeat> 
Where is one of

  • L: turn left 90 degrees,
  • R: turn right 90 degrees, or
  • F: move forward one meter,

and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.

Output

Output one line for each test case:

  • Robot i crashes into the wall, if robot i crashes into a wall. (A robot crashes into a wall if Xi = 0, Xi = A + 1, Yi = 0 or Yi = B + 1.)
  • Robot i crashes into robot j, if robots i and j crash, and i is the moving robot.
  • OK, if no crashing occurs.

Only the first crash is to be reported.

Sample Input

4
5 4
2 2
1 1 E
5 4 W
1 F 7
2 F 7
5 4
2 4
1 1 E
5 4 W
1 F 3
2 F 1
1 L 1
1 F 3
5 4
2 2
1 1 E
5 4 W
1 L 96
1 F 2
5 4
2 3
1 1 E
5 4 W
1 F 4
1 L 1
1 F 20

Sample Output

Robot 1 crashes into the wall
Robot 1 crashes into robot 2
OK
Robot 1 crashes into robot 2 思路:
直接暴力模拟这些操作。 ps:写的时候没想太多,直接强行模拟,结果发现有的地方写错了,强行改回来最后发现把代码改得巨丑无比,心态炸了。还好ac了,要不实在没法改了。
代码:
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<list>
using namespace std;
#define ll long long
const int Mod = 1e9+;
const int inf = 1e9;
const int Max = 1e5+;
vector<int>vt[Max];
//void exgcd(ll a,ll b,ll& d,ll& x,ll& y){if(!b){d=a;x=1;y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}
//ll inv(ll a,ll n){ll d, x, y;exgcd(a,n,d,x,y);return (x+n)%n;} ��Ԫ
//int gcd(int a,int b) { return (b>0)?gcd(b,a%b):a; } ��С��Լ
//int lcm(int a, int b) { return a*b/gcd(a, b); } ������
int fun1(char c){
if(c == 'N') return ;
if(c == 'E') return ;
if(c == 'S') return ;
if(c == 'W') return ;
}
int main()
{
int t,l,r,n,m,k[],cnt[],i,j,mp[][],x[],y[],v[];
char p[],z;
cin>>t;
while(t--){
int ans1=,ans2=,ans3=,flag=;
memset(mp,,sizeof(mp));
memset(v,,sizeof(v));
cin>>l>>r;
cin>>n>>m;
for(i=;i<=n;i++){
cin>>x[i]>>y[i]>>z;
mp[x[i]][y[i]] = i;
v[i] = fun1(z);
}
for(i=;i<=m;i++)
cin>>k[i]>>p[i]>>cnt[i];
for(i=;i<=m;i++){
if(p[i]=='L'){
v[k[i]] -= cnt[i];
while(v[k[i]]<)
v[k[i]] += ;
}
if(p[i]=='R'){
v[k[i]] += cnt[i]; v[k[i]] %= ;
}
if(p[i]=='F'){
if(v[k[i]]==){
for(j=;j<=cnt[i];j++){
if(mp[x[k[i]]][y[k[i]]+j]!=){
ans1 = k[i];ans2 = mp[x[k[i]]][y[k[i]]+j];
flag = ; break;
}
if(y[k[i]]+j>r){
flag = ; ans3 = k[i];break;
}
}
if(flag==){
mp[x[k[i]]][y[k[i]]+cnt[i]] = k[i];
mp[x[k[i]]][y[k[i]]] = ;
y[k[i]] += cnt[i];
}
}
if(v[k[i]]==){
for(j=;j<=cnt[i];j++){
if(mp[x[k[i]]+j][y[k[i]]]!=){
ans1 = k[i];ans2 = mp[x[k[i]]+j][y[k[i]]];
flag = ; break;
}
if(x[k[i]]+j>l){
flag = ; ans3 = k[i];break;
}
}
if(flag==){
mp[x[k[i]]+cnt[i]][y[k[i]]] = k[i];
mp[x[k[i]]][y[k[i]]] = ;
x[k[i]] += cnt[i];
}
}
if(v[k[i]]==){
for(j=;j<=cnt[i];j++){
if(mp[x[k[i]]][y[k[i]]-j]!=){
ans1 = k[i];ans2 = mp[x[k[i]]][y[k[i]]-j];
flag = ; break;
}
if(y[k[i]]-j<=){
flag = ; ans3 = k[i];break;
}
}
if(flag==){
mp[x[k[i]]][y[k[i]]-cnt[i]] = k[i];
mp[x[k[i]]][y[k[i]]] = ;
y[k[i]] -= cnt[i];
}
}
if(v[k[i]]==){
for(j=;j<=cnt[i];j++){
if(mp[x[k[i]]-j][y[k[i]]]!=){
ans1 = k[i];ans2 = mp[x[k[i]]-j][y[k[i]]];
flag = ; break;
}
if(x[k[i]]-j<=){
flag = ; ans3 = k[i];break;
}
}
if(flag==){
mp[x[k[i]]-cnt[i]][y[k[i]]] = k[i];
mp[x[k[i]]][y[k[i]]] = ;
x[k[i]] -= cnt[i];
}
}
}
if(flag!=)
break;
}
if(flag == ) cout<<"OK"<<endl;
else if(flag == ) cout<<"Robot "<<ans1<<" crashes into robot "<<ans2<<endl;
else if(flag == ) cout<<"Robot "<<ans3<<" crashes into the wall"<<endl;
}
return ;
}

打完后看了下室友的代码,越发觉得自己是个智障了。。。。

室友代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int MAX=1e2+;
const double eps=1e-;
#define INF 0x7fffffff
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
struct num{int x,y,fac;}a[MAX];
//bool cmp(const num &x, const num &y){return x.l==y.l?x.r<y.r:x.l<y.l;}
int flag,mx,my,n,m; void wrong(int x,int y,int i)
{
if(x==||x==mx+||y==||y==my+)
printf("Robot %d crashes into the wall\n",i),flag=;
else
{
int d=;
FOR(j,,n)
{
if(j==i) continue;
else if(a[j].x==x&&a[j].y==y)
d=j;
}
if(d)
{
printf("Robot %d crashes into robot %d\n",i,d);
flag=;
}
}
} void turn(int i,char ch,int t)
{
if(!flag) return;
if(ch=='L')
a[i].fac=(a[i].fac-t%+)%;
else if(ch=='R')
a[i].fac=(a[i].fac+t%)%;
else
while(t--)
{
if(a[i].fac==)
a[i].y++;
if(a[i].fac==)
a[i].x++;
if(a[i].fac==)
a[i].y--;
if(a[i].fac==)
a[i].x--;
wrong(a[i].x,a[i].y,i);
if(!flag)
break;
}
} int main()
{
int T,x,y;
char ch;
cin>>T;
while(T--)
{
cin>>mx>>my;
flag=;
cin>>n>>m;
FOR(i,,n)
{
cin>>x>>y>>ch;
a[i].x=x,a[i].y=y;
if(ch=='N') a[i].fac=;
if(ch=='E') a[i].fac=;
if(ch=='S') a[i].fac=;
if(ch=='W') a[i].fac=;
}
FOR(i,,m)
{
int num,t;
cin>>num>>ch>>t;
if(flag)
turn(num,ch,t);
}
if(flag)
cout<<"OK"<<endl;
}
return ;
}

耗时都是16ms,但空间复杂度和可读性差很多啊。。。

poj2632 【模拟】的更多相关文章

  1. poj2632 模拟

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8388   Accepted: 3631 D ...

  2. POJ-2632 Crashing Robots模拟

    题目链接: https://vjudge.net/problem/POJ-2632 题目大意: 在一个a×b的仓库里有n个机器人,编号为1到n.现在给出每一个机器人的坐标和它所面朝的方向,以及m条指令 ...

  3. POJ2632 Crashing Robots(模拟)

    题目链接. 分析: 虽说是简单的模拟,却调试了很长时间. 调试这么长时间总结来的经验: 1.坐标系要和题目建的一样,要不就会有各种麻烦. 2.在向前移动过程中碰到其他的机器人也不行,这个题目说啦:a ...

  4. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  5. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  6. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  7. HTML 事件(四) 模拟事件操作

    本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4.  ...

  8. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

  9. webapp应用--模拟电子书翻页效果

    前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...

随机推荐

  1. HDMI接口的PCB设计

    1.定义 HDMI的全称是“HighDefinitionMultimedia”,即:高清多媒体接口. HDMI在引脚上和DVI兼容,只是采用了不同的封装.与DVI相比.HDMI可以传输数字音频信号,并 ...

  2. odoo仓库单据产品过滤写法

    def onchange_picking_type_id(self, cr, uid,ids, picking_type_id, context=None): if picking_type_id i ...

  3. odoo生产单原材料报表

    原材料表: 需求量:生产单里面mrp_production里面的需求数量,这里不能直接和产品相连,因为生产单里面是原材料而产品表里是成品,通过物料清单里的bom表与产品表相连 select t6.产品 ...

  4. HDU3062&&HDU1814

    Preface 两道2-SAT模板题. HDU3062 看题目就一眼2-SAT.一对夫妻看成一个变量,之间的矛盾可以看成限制. 考虑不同席的限制,相当于选了\(i\)就不选\(j\),即必选\(j'\ ...

  5. 51Nod 1705 七星剑

    一道很新颖的概率DP,我看数据范围还以为是有指数级别的复杂度的呢 记得有人说期望要倒着推,但放在这道题上,就咕咕了吧. 我们考虑正着概率DP,设\(fi\)表示将剑升到\(i\)颗星花费的期望,这样我 ...

  6. 【强化学习】python 实现 saras 例一

    本文作者:hhh5460 本文地址:https://www.cnblogs.com/hhh5460/p/10146554.html 说明:将之前 q-learning 实现的例一,用 saras 重新 ...

  7. eclipse取消自动输入提示

    在设置Eclipse自动提示后,按a-z都会显示提示,但是我们需要键入Enter才会输入,而默认的所有都键入,非常弱智,可采用下面方法设置. 1,先找到相关的插件: window -> show ...

  8. ASP.NET Core使用TopShelf部署Windows服务

    asp.net core很大的方便了跨平台的开发者,linux的开发者可以使用apache和nginx来做反向代理,windows上可以用IIS进行反向代理. 反向代理可以提供很多特性,固然很好.但是 ...

  9. Linux Namespace : PID

    PID namespace 用来隔离进程的 PID 空间,使得不同 PID namespace 里的进程 PID 可以重复且互不影响.PID namesapce 对容器类应用特别重要, 可以实现容器内 ...

  10. Centos 6.9下部署Oracle 11G数据库环境的操作记录

    操作系统:Centos6.9(64Bit)Oracle:11g .11.2.0.4.0版本Ip地址:172.16.220.139 废话不多说了,下面记录安装过程:1)安装桌面环境 [root@vm01 ...