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:

command description
move-on keep moving with the current speed and direction
accelerate increase the speed by 1
brake decrease the speed by 1 (does not go below 0!)
left turn 45 degrees left (decrease direction by 1)
right turn 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写完。

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

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int N=;
int n,m,T,mx,tot,times,x,y,d,mn,speed,len;
char op[N],mp[N][N];
const int dx[]={,,,,,-,-,-},dy[]={-,-,,,,,,-};
struct P{ int x,y,d,speed,id; }p[N*N]; void up(int &x){ if (x<mx) x++; }
void dn(int &x){ if (x) x--; } int main(){
scanf("%d",&T);
for (int cas=; cas<=T; cas++){
scanf("%d%d",&n,&m); printf("Scenario #%d:\n",cas);
for (int i=; i<n; i++) scanf("%s",mp[i]);
scanf("%d",&times);
for (int tt=; tt<times; tt++){
scanf("%d%d%d%d",&x,&y,&d,&mx);
speed=tot=; bool cr=;
scanf("%s",op); len=strlen(op);
for (int i=; i<len; i++){
if (op[i]=='a') up(speed);
if (op[i]=='b') dn(speed);
if (op[i]=='l') d=(d+)%;
if (op[i]=='r') d=(d+)%;
bool flag=;
for (int j=; j<speed; j++){
x+=dx[d]; y+=dy[d];
if (mp[y][x]=='.') flag=;
if (mp[y][x]=='W') { printf("%d %d %d %d crashed\n",x,y,d,speed); cr=; break; }
if (mp[y][x]=='s') p[tot++]=(P){x,y,d,speed,i};
}
if (flag) speed=;
if (cr) break;
}
if (!cr) printf("%d %d %d %d\n",x,y,d,speed);
for (int i=; 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);
}
puts("");
}
return ;
}

[POJ1801]Formula Racing(模拟)的更多相关文章

  1. POJ 3672 Long Distance Racing (模拟)

    题意:给定一串字符,u表示是上坡,d表示下坡,f表示平坦的,每个有不同的花费时间,问你从开始走,最远能走到. 析:直接模拟就好了,没什么可说的,就是记下时间时要记双倍的,因为要返回来的. 代码如下: ...

  2. PKUSC2018训练日程(4.18~5.30)

    (总计:共66题) 4.18~4.25:19题 4.26~5.2:17题 5.3~5.9: 6题 5.10~5.16: 6题 5.17~5.23: 9题 5.24~5.30: 9题 4.18 [BZO ...

  3. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  4. Lucky and Good Months by Gregorian Calendar - POJ3393模拟

    Lucky and Good Months by Gregorian Calendar Time Limit: 1000MS Memory Limit: 65536K Description Have ...

  5. (转) Deep Reinforcement Learning: Playing a Racing Game

    Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...

  6. HDUOJ-------1052Tian Ji -- The Horse Racing(田忌赛马)

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  7. poj1472[模拟题]

    Instant Complexity Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2017   Accepted: 698 ...

  8. HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Fraction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. HUNNU11342:Chemistry(模拟)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11342 Problem description The ch ...

随机推荐

  1. 【BZOJ 1592】[Usaco2008 Feb]Making the Grade 路面修整 dp优化之转移变状态

    我们感性可证离散(不离散没法做),于是我们就有了状态转移的思路(我们只考虑单不减另一个同理),f[i][j]到了第i块高度为j的最小话费,于是我们就可以发现f[i][j]=Min(f[i-1][k]) ...

  2. 用JavaScript实现一个简单的树结构

    数据源用数组混json结构,实现了基本的功能.效率一般,跟 dhtree 梅花雪树对比了下,都差不多. (ps感觉比dhtree快点,跟梅花雪树差不多,个人测试) 这个实现树的原理是根据json,不断 ...

  3. RPC-Thrift(二)

    TTransport TTransport负责数据的传输,先看类结构图. 阻塞Server使用TServerSocket,它封装了ServerSocket实例,ServerSocket实例监听到客户端 ...

  4. 【洛谷 P1251】 餐巾计划问题 (费用流)

    题目链接 我做的网络流24题里的第一题.. 想是不可能想到的,只能看题解. 首先,我们拆点,将一天拆成晚上和早上,每天晚上会受到脏餐巾(来源:当天早上用完的餐巾,在这道题中可理解为从原点获得),每天早 ...

  5. 【洛谷 SP283】NAPTIME - Naptime(DP)

    题目链接 先考虑如果只有一天,那么该怎么做. 设\(f[i][j][1]\)表示前\(i\)个小时睡了\(j\)个小时并且第\(j\)个小时正在睡觉时的最大体力,\(f[i][j][1]\)表示前\( ...

  6. 【洛谷 P1364】医院设置(树的重心)

    树的重心的定义: 树若以某点为根,使得该树最大子树的结点数最小,那么这个点则为该树的重心,一棵树可能有多个重心. 树的重心的性质: 1.树上所有的点到树的重心的距离之和是最短的,如果有多个重心,那么总 ...

  7. 转:java读取配置文件的几种方法

    转自: http://www.iteye.com/topic/56496 在现实工作中,我们常常需要保存一些系统配置信息,大家一般都会选择配置文件来完成,本文根据笔者工作中用到的读取配置文件的方法小小 ...

  8. mysql五-1:单表查询

    一 介绍 本节内容: 查询语法 关键字的执行优先级 简单查询 单条件查询:WHERE 分组查询:GROUP BY HAVING 查询排序:ORDER BY 限制查询的记录数:LIMIT 使用聚合函数查 ...

  9. 千万不要使用xfce和KDE版Manjaro Linux--之荒谬言论

    Manjaro Linux 使用经验: ①千万不要使用xfce版,虽然性能上廉价,但是吃亏,调声音80%几率卡死调不了,托盘图标很容易不响应!关机的Beep声,分分钟吓死人!按照网上各种方法弄,下次开 ...

  10. C++类学习

    一.C++类的定义     C++中使用关键字 class 来定义类, 其基本形式如下:class 类名{ public: //行为或属性  protected: //行为或属性 private: / ...