快速切题 poj2632
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7799 | Accepted: 3388 |
Description
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 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
- 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 简单的模拟
应用时:15min
实际用时:1h40min
问题:碰撞的先后次序
#include<cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int A,B,n,m;
int robot[][];
char rbuff[];
int dir[];
const int dx[]={,,,-};
const int dy[]={,,-,};
int action[][];
int tx,ty;
int ansr;
bool between(int aim,int gap){
int sx=robot[gap][];
int sy=robot[gap][];
int mingx=min(sx,tx);
int maxgx=max(sx,tx);
int mingy=min(sy,ty);
int maxgy=max(sy,ty);
int ax=robot[aim][];int ay=robot[aim][];
if(ax>=mingx&&ax<=maxgx&&ay>=mingy&&ay<=maxgy){
if(ansr==)ansr=aim;
else {
if(abs(robot[ansr][]-sx)>=abs(ax-sx)&&abs(robot[ansr][]-sy)>=abs(ay-sy)){
ansr=aim;
}
}
return true;
}
return false;
}
void solve(){
ansr=;
for(int i=;i<m;i++){
int rob=action[i][];
int rep=action[i][];
if(action[i][]==){
robot[rob][]=(robot[rob][]+-rep%)%;
}
else if(action[i][]==){
robot[rob][]=(robot[rob][]+rep%)%;
}
else{
bool fl=false;
tx=robot[rob][]+rep*dx[robot[rob][]];
ty=robot[rob][]+rep*dy[robot[rob][]];
for(int j=;j<=n;j++){
if(j==rob)continue;
if(between(j,rob)){
fl=true;
}
}
if(fl){
printf("Robot %d crashes into robot %d\n",rob,ansr);return ;
}
if(tx<||tx>A||ty<||ty>B){
printf("Robot %d crashes into the wall\n",rob);return ;
}
robot[rob][]=tx;
robot[rob][]=ty;
}
}
puts("OK");
} int main(){
#ifndef ONLINE_JUDGE
freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE
dir['N']=;dir['E']=;dir['S']=;dir['W']=;
dir['L']=;dir['R']=;dir['F']=;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&A,&B,&n,&m);
for(int i=;i<=n;++i){
scanf("%d%d%s",robot[i],robot[i]+,rbuff);
robot[i][]=dir[rbuff[]];
}
for(int i=;i<m;i++){
scanf("%d%s%d",action[i],rbuff,action[i]+);
action[i][]=dir[rbuff[]];
}
solve();
}
return ;
}
快速切题 poj2632的更多相关文章
- 快速切题sgu127. Telephone directory
127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 快速切题 sgu123. The sum
123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...
- 快速切题 sgu120. Archipelago 计算几何
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...
- 快速切题 sgu119. Magic Pairs
119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...
- 快速切题 sgu118. Digital Root 秦九韶公式
118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...
- 快速切题 sgu117. Counting 分解质因数
117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...
- 快速切题 sgu116. Index of super-prime bfs+树思想
116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...
- 快速切题 sgu115. Calendar 模拟 难度:0
115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...
随机推荐
- 0x30、0x37
1.write_date(0x30+shi)加0x30是什么意思 答: 将数字0-9转化为字符'0'-'9' 1.write_date(0x37+bai)加0x37是什么意思 答: 将大于9的数字转化 ...
- Python3基础 getattr 获取对象的指定属性值
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 高通平台启动log概述(PBL log、sbl1 log、kernel log)【转】
本文转自:https://blog.csdn.net/RadianceBlau/article/details/78416776?utm_source=blogxgwz9 高通平台启动log概述(PB ...
- Centos用yum方式安装nodejs和npm
要通过 yum 来安装 nodejs 和 npm 需要先给 yum 添加 epel 源 ##添加 epel 源 rpm -ivh http://download.fedoraproject.org/p ...
- [bzoj 1270][BeijingWc2008]雷涛的小猫
Description 雷涛的小猫雷涛同学非常的有爱心,在他的宿舍里,养着一只因为受伤被救助的小猫(当然,这样的行为是违反学 生宿舍管理条例的). 在他的照顾下,小猫很快恢复了健康,并且愈发的活泼可 ...
- [JVM] - 一份<自己动手写Java虚拟机>的测试版
go语言下载 配置GOROOT(一般是自动的),配置GOPATH(如果想自己改的话) 参照<自己动手写Java虚拟机> > 第一章 指令集和解释器 生成了ch01.exe文件 这里还 ...
- MVC ---- 标准查询运算符
标准查询运算符:定义在System.Linq.Enumerable类中的50多个为IEnumerable<T>准备的扩展方法,这些方法用来 对它操作的集合进行查询筛选. 筛选集合Where ...
- bnu 51636 Squared Permutation 线段树
Squared Permutation Time Limit: 6000ms Memory Limit: 262144KB 64-bit integer IO format: %lld Ja ...
- 《剑指offer》第三十五题(复杂链表的复制)
// 面试题35:复杂链表的复制 // 题目:请实现函数ComplexListNode* Clone(ComplexListNode* pHead),复 // 制一个复杂链表.在复杂链表中,每个结点除 ...
- JavaScript算法相关
1. 不使用循环,创建一个长度为100的数组,并且每个元素的值等于它的下标? Array.apply(null, {length: N}).map(Function.call, Number); Ar ...