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 ...
随机推荐
- Oracle 多实例如何通过EM进行访问-portlist.ini
[root@redhat4 install]# pwd/u01/app/oracle/product/11.2.0/dbhome_1/install[root@redhat4 install]# mo ...
- hdu 1575 Tr A (矩阵快速幂入门题)
题目 先上一个链接:十个利用矩阵乘法解决的经典题目 这个题目和第二个类似 由于矩阵乘法具有结合律,因此A^4 = A * A * A * A = (A*A) * (A*A) = A^2 * A^2.我 ...
- BZOJ_1030_[JSOI2007]_文本生成器_(AC自动机+DP)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1030 给出一些单词,问长度为\(m\)的文章有多少文章中出现过任意一个或多个单词. 分析 文章 ...
- SDOI 2010 and SXOI 2014 地精部落 (递推)
用E[i,j]表示共有i个数字,以1..j开头且一开始下降的方案数的总和.则我们有: E[i,j]:=E[I,J-1]+E[i-1,i-j] 我们先来证明上升与下降的方案是一一对应的. 事实上,若有a ...
- facebook海量图片存储系统与淘宝TFS系统比较
本篇论文的原文可谓通俗易懂.行云流水.结构清晰.图文并茂……正如作者所说的——"替换Facebook的图片存储系统就像高速公路上给汽车换轮子,我们无法去追求完美的设计……我们花费了很多的注意 ...
- MyEclipse的快捷使用(含关联源码和Doc的方式)
删除行代码 :在Eclipse中将光标移至待删除的行上,然后按Ctrl+d 组合键 快速导入包 :在Eclipse中将光标移至相应的类上面,按Ctrl+Shift+M 组合键 批量行注释 :Ctrl+ ...
- Mybatis学习——一对一关联表查询
1.SQL语句建表 CREATE TABLE teacher( t_id ) ); CREATE TABLE class( c_id ), teacher_id INT ); ALTER TABLE ...
- 【Servlet】doGet()与doPost()的区别
doGet与doPost的区别 .Servlet接口只定义了一个服务方法--service .当发出客户端请求时,调用service方法并传递一个请求和响应对象 .使用时经常在doPost()中调用d ...
- mysql 自旋锁
自旋(spin)是一种通过不间断地测试来查看一个资源是否变为可用状态的等待操作,用于仅需要等待很短的时间等待所需资源的场景.使用自旋这种“空闲循环(busy-loop)”来完成资源等待的方式要比通过上 ...
- gtid
GTID的全称为 global transaction identifier,可以翻译为全局事务标示符,GTID在原始master上的事务提交时被创建.GTID需要在全局的主-备拓扑结构中保持唯一性, ...