Traffic Jam in Flower Town

题目链接:

http://acm.hust.edu.cn/vjudge/contest/126546#problem/I

Description


Having returned from Sun City, Dunno told all his friends that every shorty may have a personal
automobile. Immediately after that so many citizens took a fancy of becoming road-users, that Bendum
and Twistum had to make a mass production of cars on soda water with syrup. Now traffic jams from
several cars occasionally appear on the crossing of Bell-flower Street and Daisy Street.
Bell-flower Street goes from the South to the North and has two driving paths. It has the right driving,
i. e. automobiles move from the South to the North on the Eastern path and from the North to the South
on the Western path. Daisy Street is single-pathed, and it is perpendicular to Bell-flower Street. There is
one-way movement on it, but its driving direction is organized in such a way that automobiles drive away
from the crossroad in two opposite directions (see the picture).
Yesterday on his way home Dunno saw cars standing in a traffic jam
on Bell-flower Street from different sides of the crossing with Daisy
Street. Some of the drivers wanted to go forward, some wanted to turn
right or left. An automobile can pass the crossing in one second, but if
the driver is turning left, he first have to let pass all oncoming vehicles,
going forward and to the right. How many seconds did it take all the
cars to pass the crossing, providing that no other cars drove up to the
crossing?

Input


The first line contains the sequence of symbols “F”, “L” and “R”, describing directions in which drivers who
arrived to the crossing from the South wanted to go. “F” stands for those drivers who were going forward,
“L” is for those who were turning left, and “R” is for those who were turning right. Automobiles are listed
in the order from the closest to the crossing to the farthest one. The second line contains the description
of the cars, arrived to the crossing from the North, in the same form. Both sequences have length from 1
to 1 000.

Output


Output time in seconds, which took all the cars to pass the crossing.

Examples


RLF
FF
4
L
L
1

Explanation


In the first example we number the cars from 1 to 5 in the order described in the input data. Then
in the first second the crossing was passed by the first and the fourth cars because they didn’t cause
an obstruction to each other. Then the second car was turning left and had to let the fifth car pass. As
a result, at each of the following three seconds only one car passed the crossing, and their order was as
follows: the fifth one, the second one and the third one.
In the second example the cars didn’t cause any obstruction to each other and turned simultaneously.


##题意:

如图所示的道路通行方向.
左转时要先让对面的直行和右转先走.
给出两个方向来的车辆将要走的方向.
给出总共需要的时间. (不冲突的方向可以同时走).


##题解:

直接模拟一遍就可以了.
这题读题比做题要难呀.
队友写的代码,我就不重复写了,挂上来做个记录.


##代码:
``` cpp
#include
#include
#include
using namespace std;

char s1[1005], s2[1005];

int main() {

gets(s1); gets(s2);

int len1 = strlen(s1);

int len2 = strlen(s2);

int pos1 = 0, pos2 = 0;

int ans = 0;

while (1) {

if (pos1 == len1 && pos2 == len2) break;

if (pos1 == len1) {ans++; pos2++; continue;}

if (pos2 == len2) {ans++; pos1++; continue;}

if (s1[pos1] == 'F' && s2[pos2] == 'F') {

pos1++, pos2++; ans++; continue;

}

if (s1[pos1] == 'R' && s2[pos2] == 'R') {

pos1++, pos2++; ans++; continue;

}

if (s1[pos1] == 'R' && s2[pos2] == 'F') {

pos1++, pos2++; ans++; continue;

}

if (s1[pos1] == 'F' && s2[pos2] == 'R') {

pos1++, pos2++; ans++; continue;

}

if (s1[pos1] == 'L' && s2[pos2] == 'L') {

pos1++, pos2++; ans++; continue;

}

if (s1[pos1] == 'L') {

pos2++; ans++; continue;

}

if (s2[pos2] == 'L') {

pos1++; ans++; continue;

}

}

printf("%d\n", ans);

return 0;

}

Gym 100507I Traffic Jam in Flower Town (模拟)的更多相关文章

  1. ural 2020 Traffic Jam in Flower Town(模拟)

    2020. Traffic Jam in Flower Town Time limit: 1.0 secondMemory limit: 64 MB Having returned from Sun ...

  2. Gym 101775C - Traffic Light - [思维题]

    题目链接:http://codeforces.com/gym/101775/problem/C 题意: 给出 $N$ 个红绿灯,又给出 $N+1$ 个距离 $S_i = S_0,S_1, \cdots ...

  3. JAM计数法(模拟)

    题目描述 Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个数字的位数都是相同的(使用相同个数的字母),英文字 ...

  4. Gym 100851E Easy Problemset (水题,模拟)

    题意:给定 n 个裁判,然后每个都一些题目,现在要从每一个按顺序去选出 k 个题,并且这 k 个要按不递减顺序,如果没有,就用50补充. 析:就按他说的来,直接模拟就好. 代码如下: #pragma ...

  5. UVaLive 6581 && Gym 100299B What does the fox say? (模拟+STL)

    题意:给定一些动物的叫声,然后再定某些动物的叫声,让你去除这些叫声后得到的叫声. 析:先存储所有的叫声,然后用map来记录其他的叫声,在输出时再判定一下就好. 代码如下: #pragma commen ...

  6. Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )

    题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...

  7. UVALive 2664 One-way traffic

    One-way traffic Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Or ...

  8. LightOJ 1291 Real Life Traffic

    Real Life Traffic Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on LightOJ. O ...

  9. Java实现One-way traffic(单向交通)

    One-way traffic In a certain town there are n intersections connected by two- and one-way streets. T ...

随机推荐

  1. RecyclerView(4)简单示例

    1,RecyclerViewFrgmt import com.example.adapter.R; import android.app.Fragment; import android.os.Bun ...

  2. iOS学习笔记:frame,bound,center, anchorPoint

    frame: View在它的Super View坐标系里的坐标 bound: 用来定义View自身坐标系和边界的Rect,Rect的原点表示View自身坐标系的原点坐标.举个例子: 一般情况下boun ...

  3. C++中关于指针初始化和使用NULL的理解

    1.严禁使用未被初始化的指针:C++创建指针的时候,只分配存储地址的内存,并不会分配存储数据的内存,所以指针可能指向任何位置. (1)使用解除运算符(*)之前,一定要对指针初始化,否则若声明的指针刚好 ...

  4. TC SRM 593 DIV1 250(dfs)

    这图最多3色就可以 搜2就行了 #include <iostream> #include<cstdio> #include<cstring> #include< ...

  5. 移动APP服务端API设计应该考虑到的问题

    2014年,移动APP的热度丝毫没有减退,并没有像桌面软件被WEB网站那样所取代, 不但如此,越来越多的传统应用.网站也都开始制作自己的移动APP,也就是我们常说的IOS客户端.android客户端. ...

  6. codevs 1197 Vigenère密码

    开始做NOIP啦.. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  7. 基于Live555,ffmpeg的RTSP播放器直播与点播

    基于Live555,ffmpeg的RTSP播放器直播与点播 多路RTSP高清视频播放器下载地址:http://download.csdn.net/detail/u011352914/6604437多路 ...

  8. mysql教程-触发器

    触发器 1. mysql触发器 情景说明 情景设置,如图,当我们点击了购买,将会发生什么? 现有如下两张表 商品表 编号(id)名称(name)价格(price)库存(stock) 1F2战斗机100 ...

  9. DBCP连接池原理分析及配置用法

    DBCP连接池介绍 ----------------------------- 目前 DBCP 有两个版本分别是 1.3 和 1.4. DBCP 1.3 版本需要运行于 JDK 1.4-1.5 ,支持 ...

  10. map用法详解

    转自:http://www.kuqin.com/cpluspluslib/20071231/3265.html Map是 STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在 ...