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. CRC校验码

    循环冗余校验码(CRC)的基本原理是:在K位信息码后再拼接R位的校验码,整个编码长度为N位,因此,这种编码也叫(N,K)码.对于一个给定的(N,K)码,可以证明存在一个最高次幂为R的多项式G(x)(R ...

  2. 自己动手实现STL:前言

    一.前言 最近,刚看完<STL源码剖析>,深深被实现STL库的那些的大牛们所折服.同时又感觉自己与大牛们差距之大,便萌生深入学习之意.如果仅仅只是看看<STL源码剖析>的话,又 ...

  3. Codeforces 383A - Milking cows

    原题地址:http://codeforces.com/problemset/problem/383/A 题目大意:有 n 头奶牛,全部看着左边或者右边,现在开始给奶牛挤奶,给一头奶牛挤奶时,所有能看到 ...

  4. 函数ut_bit_set_nth

    /*****************************************************************//** Sets the nth bit of a ulint. ...

  5. WebClient+Fiddler2完美搭配下载远程页面信息

    WebClient可以下载远程页面信息,这个大家应该都知道,核心代码如下: WebClient web = new WebClient(); string url = String.Format(&q ...

  6. LeetCode Letter Combinations of a Phone Number 电话号码组合

    题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成. 思路:尼玛,一直RE,题意都不说0和1怎么办.DP解决. class Solution { public: ...

  7. zoj 3659 Conquer a New Region

    // 给你一颗树 选一个点,从这个点出发到其它所有点的权值和最大// i 到 j的最大权值为 i到j所经历的树边容量的最小值// 第一感觉是树上的dp// 后面发现不可以// 看了题解说是并查集// ...

  8. 编译安装lnmp

    http://wenku.baidu.com/view/ec45d5dd28ea81c758f578cc.html

  9. 多线程程序设计学习(2)之single threaded execution pattern

    Single Threaded Execution Pattern[独木桥模式] 一:single threaded execution pattern的参与者--->SharedResourc ...

  10. 在linux的shell里访问一个URL

    在linux上访问一个网址有四种方法 1.elinks,用法举例: [weishusheng@centOS6 ~]$ elinks -dump http://www.baidu.com 2. wget ...