Gym 100507I Traffic Jam in Flower Town (模拟)
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 (模拟)的更多相关文章
- 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 ...
- Gym 101775C - Traffic Light - [思维题]
题目链接:http://codeforces.com/gym/101775/problem/C 题意: 给出 $N$ 个红绿灯,又给出 $N+1$ 个距离 $S_i = S_0,S_1, \cdots ...
- JAM计数法(模拟)
题目描述 Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个数字的位数都是相同的(使用相同个数的字母),英文字 ...
- Gym 100851E Easy Problemset (水题,模拟)
题意:给定 n 个裁判,然后每个都一些题目,现在要从每一个按顺序去选出 k 个题,并且这 k 个要按不递减顺序,如果没有,就用50补充. 析:就按他说的来,直接模拟就好. 代码如下: #pragma ...
- UVaLive 6581 && Gym 100299B What does the fox say? (模拟+STL)
题意:给定一些动物的叫声,然后再定某些动物的叫声,让你去除这些叫声后得到的叫声. 析:先存储所有的叫声,然后用map来记录其他的叫声,在输出时再判定一下就好. 代码如下: #pragma commen ...
- Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )
题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...
- UVALive 2664 One-way traffic
One-way traffic Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Or ...
- LightOJ 1291 Real Life Traffic
Real Life Traffic Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on LightOJ. O ...
- Java实现One-way traffic(单向交通)
One-way traffic In a certain town there are n intersections connected by two- and one-way streets. T ...
随机推荐
- C++ STL之list容器的基本操作
由于list和vector同属于序列式容器,有很多相同的地方,而上一篇中已经写了vector,所以这一篇着重写list和vector的不同之处和特有之处. 特别注意的地方: (1)STL中迭代器容器中 ...
- POJ 3185 The Water Bowls (高斯消元 求最小步数)
题目链接 题意:有20个数字,0或1.如果改变一个数的状态,它左右两边的两个数的状态也会变反.问从目标状态到全0,至少需要多少次操作. 分析: 和上一题差不多,但是比上一题还简单,不多说了,但是在做题 ...
- 使用hibernate annotation 为非空列加上默认值
在网上查了很多资料都没找到如何为非空列加上默认值 以前的做法是给字段一个初始值,加上dynamic-insert属性 换了annotation了以后没有找到如何设置dynamic-insert属性 但 ...
- UVa 437 (变形的LIS) The Tower of Babylon
题意: 有n种类型的长方体,每种长方体的个数都有无限个.当一个长方体的长和宽分别严格小于另一个长方体的长和宽的时候,才可以把这个放到第二个上面去.输出这n种长方体能组成的最大长度. 分析: 虽说每种都 ...
- CodeForces Round #278 (Div.2) (待续)
A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...
- C#计算程序执行速度
long t1 = DateTime.Now.Ticks; //执行程序,例如处理100个文件 long t2 = DateTime.Now.Ticks; Response.Write("执 ...
- Test语言编译器V0.8
感觉这个挺好耍的,书上的代码有错误,而且功能有限. 一.词法分析 特点: (1)可对中文进行识别:(2)暂不支持负数,可以在读入‘-'时进行简单标记后就能对简单负数进行识别了. #include &l ...
- php服务器安装memcache
https://pecl.php.net/get/memcache-3.0.8.tgz wget https://pecl.php.net/get/memcache-3.0.8.tgzgzip -d ...
- LeetCode Linked List Cycle 单链表环
题意:给一个单链表,判断其是否出现环! 思路:搞两个指针,每次,一个走两步,另一个走一步.若有环,他们会相遇,若无环,走两步的指针必定会先遇到NULL. /** * Definition for si ...
- 【C#学习笔记】获得本机IP
using System; using System.Net; namespace ConsoleApplication { class Program { static void Main(stri ...