poj2632 累死了
题意:
给定A*B的格子,放入N个机器人,每个机器人初始位置及朝向给定。给定M条指令。指令类型有三种:
1、L:左转90° 2、R:右转90° 3、F:前进一格
问执行指令过程中机器人是否发生碰撞,碰撞包括碰墙或碰其他机器人。安全执行完所有指令输出OK。(程序只需输出发生的第一次碰撞)
第一发我定义了一个cnate[20000][20000]直接空间爆炸
第二发不知道走过的路径中碰到机器人的话也算碰撞
第三发到第五发坐标建立错误(看图就知道了) 最后实在不知道了就看了下别人的题解...

最后总结一下:这种模拟题一定要根据题目意思来,题目是什么就怎么模拟,唉,可怜我这种英语渣渣。
这道题前前后后做了四个小时...
#include<cstdio>
#include<cstring>
#include<cmath>
const int maxn = + ;
int cnate[maxn][maxn];
int dx[] = {,,,-};
int dy[] = {,,-,};
int zhuang=,beizhuang=;
char s[];
using namespace std;
struct Robots{
int x,y,d;
}r[maxn];
int main()
{
int n,m,e=,flag;
int t;int a,b;
scanf("%d",&t);getchar();
while(t--){
flag=;
memset(cnate,,sizeof(cnate));
scanf("%d %d",&a,&b);scanf("%d %d",&n,&m);
for(int i=;i<=n;i++){
scanf("%d %d",&r[i].x,&r[i].y);
scanf("%s",s);cnate[r[i].y][r[i].x]=i; //就是这里,建立坐标
switch(s[]){
case 'N':r[i].d=;break;
case 'E':r[i].d=;break;
case 'S':r[i].d=;break;
case 'W':r[i].d=;break;
}
}
char act[];int num,rep;
while(m--){
scanf("%d %s %d",&num,act,&rep);
if(!flag){
if(act[]=='L') r[num].d=((r[num].d-rep)%+)%;
else if(act[]=='R') r[num].d=(r[num].d+rep)%;
else{
cnate[r[num].y][r[num].x] = ;
for(int i=;i<rep;++i){
r[num].x+=dx[r[num].d];
r[num].y+=dy[r[num].d];
if(r[num].x<=||r[num].x>a||r[num].y<=||r[num].y>b){
zhuang=num;flag=;break;
}
else if(cnate[r[num].y][r[num].x]){
zhuang=num;beizhuang=cnate[r[num].y][r[num].x];
flag=;break;
}
}
if(!flag) cnate[r[num].y][r[num].x] = num;
}
}
}
if(flag==) printf("Robot %d crashes into the wall\n", zhuang);
else if(flag==) printf("Robot %d crashes into robot %d\n", zhuang, beizhuang);
else printf("OK\n");
}
return ;
}
poj2632 累死了的更多相关文章
- POJ-2632 Crashing Robots模拟
题目链接: https://vjudge.net/problem/POJ-2632 题目大意: 在一个a×b的仓库里有n个机器人,编号为1到n.现在给出每一个机器人的坐标和它所面朝的方向,以及m条指令 ...
- 为了用python计算一个汉字的中心点,差点没绞尽脑汁活活累死
为了用python计算一个汉字的中心点,差点没绞尽脑汁活活累死
- POJ2632
#include<stdio.h> #include<string.h> #include<algorithm> #include<cmath> usi ...
- hadoop多次搭建后,完整总结(累死宝宝了,搭建了十多遍了)
1.安装JDK1.1上传运用软件FileZilla,将windows上的jdk压缩包放到linux的root目录下 1.2解压jdk #创建文件夹 mkdir /usr/java(不要挂在在" ...
- poj2632 Crashing Robots
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9859 Accepted: 4209 D ...
- poj2632 模拟
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8388 Accepted: 3631 D ...
- POJ2632——Crashing Robots
Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful pl ...
- POJ2632 Crashing Robots(模拟)
题目链接. 分析: 虽说是简单的模拟,却调试了很长时间. 调试这么长时间总结来的经验: 1.坐标系要和题目建的一样,要不就会有各种麻烦. 2.在向前移动过程中碰到其他的机器人也不行,这个题目说啦:a ...
- poj2632 【模拟】
In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure ...
随机推荐
- select @@identity的用法 转
用select @@identity得到上一次插入记录时自动产生的ID 如果你使用存储过程的话,将非常简单,代码如下:SET @NewID=@@IDENTITY 说明: 在一条 INSERT.SELE ...
- Python之其他数据类型
1.可命名元组:namedtuple 由nametuple可创建一个包含tuple所有功能以及其他功能的类型 class Mytuple(__builtin__.tuple) | Mytuple(x, ...
- $.ajax中contentType: “application/json” 的用法
不使用contentType: “application/json”则data可以是对象 $.ajax({ url: actionurl, type: "POST", datTyp ...
- viewpager实现进入程序之前的欢迎界面效果
用viewpager实现该效果大致需要5步 1,用support.v4包下的ViewPager.xml布局如下: <android.support.v4.view.ViewPager andro ...
- pom.xml中若出现jar not found;
pom.xml中若出现jar not found;我们可以直接在view ->tool windows ->Maven Project 中直接install
- VBA 生成带时间戳的随机数字
Function GenPasswd(length, level) Dim allstr, substr, passwd As String allstr = "0123456789abcd ...
- Linux上编辑然后执行一段脚本的机制
简要分析下刚开始提出的第二个问题, 因为没看代码,所以只是简单流程 1. 在bash里打开vim编辑文件并保存退出: bash进程fork子进程, 然后调用exec装入vim程序,wait这个子进程v ...
- 远程安装App到手机
注意: 必须是手机和电脑网络连通正常 1. 手机端安装终端模拟器. 2. 打开终端模拟器执行下面命令(也可以在adb shell中执行): su setprop service.adb.tcp.por ...
- Python之整数类型
整数:18,73,84 每一个整数都有如下的功能:class int(object): """ int(x=0) -> int or long int(x, bas ...
- LeetCode115 Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. (Hard) A subse ...