[POJ1801]Formula Racing(模拟)

Formula Racing
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 289 Accepted: 77

Description

Background
The brand new formula racing team Irarref needs your help! Irarref doesn't have any real good drivers but they want to dominate formula racing. Since fairness doesn't mean anything to them they are trying to build a fully automatic driving control which needs almost no driver interaction.
Before actually trying the automatic driving control on track and risking to crash their precious cars (they don't care much about their drivers), they want to test it in a computer simulation.
Problem
You have to simulate the movement of a car on a given track. To simplify the problem, cars can only move in 8 directions (horizontal, vertical, and diagonal) on cells of a regular 2-dimensional grid, where directions are encoded as follows:
701
6 2
543

Every turn the car executes exactly one of the following commands:
commanddescription
move-onkeep moving with the current speed and direction
accelerateincrease the speed by 1
brakedecrease the speed by 1 (does not go below 0!)
leftturn 45 degrees left (decrease direction by 1)
rightturn 45 degrees right (increase direction by 1)

In any case, a car moves its speed value in cells in its current direction and crosses all cells in-between its old and new position. When a car accelerates or brakes, its speed is adjusted before the movement of the current turn. When a car turns, its direction is changed before the movement.
The racing track is a 2-dimensional regular grid, where every cell can be: road, non-road space (but still drivable), start/goal line (also road and drivable), or wall.
Every car starts with an initial speed of 0 and has a maximum speed which it cannot exceed. When a car hits non-road space its speed is reduced to 1 in the next turn but it completes the move of this turn with its current speed. When a car hits a wall it crashes, the simulation stops immediately and there will be no next turn.
Every car is alone on the track, so you do not have to check for car/car collisions.

Input

The first line contains the number of scenarios.
For each scenario, the first line contains width w and height h of the racing track (1 <= w, h <= 1000).The following h lines contain the layout of the racing track where road, non-road-space, start/goal line, and wall are represented by "x", ".", "s", and "W", respectively. The upper left corner of the racing area is (0, 0), the lower right corner (w-1, h-1), where coordinates are given as pairs (x, y) where x-direction is horizontal and y-direction is vertical.
A line containing the number n of cars to simulate follows the track description. For every car there are two lines:
  • a line containing the initial x- and y-coordinate x and y, direction d, and maximum speed m of the car, as integers separated by single blanks, where 0 <= x <= w-1, 0 <= y <= h-1, 0 <= d <= 7, 1 <= m
  • a line containing a string whose single characters each encode one command for this car, where "m","a", "b", "l", and "r" represent move-on, accelerate, brake, left, and right, respectively; the number of commands for a car is at least 1 and at most 10000.

It is guaranteed that the initial car position is not on a wall. It is also guaranteed that the car does not leave the track area without crashing.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. For every scenario print for ever car the following information:
  • If the car did not crash print a line containing the final position (x- and y-coordinate), direction and speed of the car, all separated by single spaces.If the car did crash print a line containing the crash-point (x- and y-coordinate), direction and speed of the car at the moment of the crash and the word "crashed", all separated by single spaces.
  • For every hit of a start/goal field (a hit is counted when moving onto a start/goal field) print a line beginning with "crossing startline:", followed by a single space, the x- and y-coordinates,direction, speed and the number of the simulation turn the line was crossed or hit. The lines must be printed in the same order the start/goal fields were hit.

Print a blank line after each scenario.

Sample Input

1
12 12
WWWWWWWWWWWW
W...xxxx...W
W..xxxxxx..W
W.xxWWWWxx.W
WxxWW..WWxxW
WxxW....WxxW
WssW....WxxW
WxxWW..WWxxW
W.xxWWWWxx.W
W..xxxxxx..W
W...xxxx...W
WWWWWWWWWWWW
2
1 6 0 3
armmrarrmrrrbrmmb
1 5 0 4
ararmrramrmar

Sample Output

Scenario #1:
2 4 0 0
crossing startline: 2 6 0 1 13
5 11 5 2 crashed

Source

TUD Programming Contest 2004, Darmstadt, Germany

[Submit]   [Go Back]   [Status]   [Discuss]

英文阅读题。1h读懂题,10min写完。

纯模拟,看网上没有代码就发一份吧。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 const int N=1010;
 7 int n,m,T,mx,tot,times,x,y,d,mn,speed,len;
 8 char op[N],mp[N][N];
 9 const int dx[8]={0,1,1,1,0,-1,-1,-1},dy[8]={-1,-1,0,1,1,1,0,-1};
10 struct P{ int x,y,d,speed,id; }p[N*N];
11 
12 void up(int &x){ if (x<mx) x++; }
13 void dn(int &x){ if (x) x--; }
14 
15 int main(){
16     scanf("%d",&T);
17     for (int cas=1; cas<=T; cas++){
18         scanf("%d%d",&n,&m); printf("Scenario #%d:\n",cas);
19         for (int i=0; i<n; i++) scanf("%s",mp[i]);
20         scanf("%d",&times);
21         for (int tt=0; tt<times; tt++){
22             scanf("%d%d%d%d",&x,&y,&d,&mx);
23             speed=tot=0; bool cr=0;
24             scanf("%s",op); len=strlen(op);
25             for (int i=0; i<len; i++){
26                 if (op[i]=='a') up(speed);
27                 if (op[i]=='b') dn(speed);
28                 if (op[i]=='l') d=(d+7)%8;
29                 if (op[i]=='r') d=(d+1)%8;
30                 bool flag=0;
31                 for (int j=0; j<speed; j++){
32                     x+=dx[d]; y+=dy[d];
33                     if (mp[y][x]=='.') flag=1;
34                     if (mp[y][x]=='W') { printf("%d %d %d %d crashed\n",x,y,d,speed); cr=1; break; }
35                     if (mp[y][x]=='s') p[tot++]=(P){x,y,d,speed,i};
36                 }
37                 if (flag) speed=1;
38                 if (cr) break;
39             }
40             if (!cr) printf("%d %d %d %d\n",x,y,d,speed);
41             for (int i=0; i<tot; i++) printf("crossing startline: %d %d %d %d %d\n",p[i].x,p[i].y,p[i].d,p[i].speed,p[i].id);
42         }
43         puts("");
44     }
45     return 0;
46 }

 

转载于:https://www.cnblogs.com/HocRiser/p/8921061.html

内容概要:该题库专为研究生入学考试计算机组成原理科目设计,涵盖名校考研真题、经典教材课后习题、章节题库和模拟试题四大核心模块。名校考研真题精选多所知名高校的计算机组成原理科目及计算机联考真题,并提供详尽解析,帮助考生把握考研命题趋势与难度。经典教材课后习题包括白中英《计算机组成原理》(第5版)和唐朔飞《计算机组成原理》(第2版)的全部课后习题解答,这两部教材被众多名校列为考研指定参考书目。章节题库精选代表性考题,注重基础知识与重难点内容,帮助考生全面掌握考试大纲要求的知识点。模拟试题依据历年考研真题命题规律和热门考点,精心编制两套全真模拟试题,并附标准答案,帮助考生检验学习成果,评估应试能力。 适用人群:计划参加研究生入学考试并报考计算机组成原理科目的考生,尤其是需要系统复习和强化训练的学生。 使用场景及目标:①通过研读名校考研真题,考生可以准确把握考研命题趋势与难度,有效评估复习成效;②通过经典教材课后习题的练习,考生可以巩固基础知识,掌握解题技巧;③通过章节题库的系统练习,考生可以全面掌握考试大纲要求的各个知识点,为备考打下坚实基础;④通过模拟试题的测试,考生可以检验学习成果,评估应试能力,为正式考试做好充分准备。 其他说明:该题库不仅提供详细的题目解析,还涵盖了计算机组成原理的各个方面,包括计算机系统概述、数据表示与运算、存储器分层、指令系统、中央处理器、总线系统和输入输出系统等。考生在使用过程中应结合理论学习与实践操作,注重理解与应用,以提高应试能力和专业知识水平。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值