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 ...
随机推荐
- Android权限安全(8)ContentProvider基于URI的安全
一.provider可以通过binder得到客户的uid,然后进程权限检查. 二,provider临时权限 场景: Email的内容在provider中提供,Email的客户端可读基其内容,现在一封 ...
- Awesome Algorithms
Awesome Algorithms A curated list of awesome places to learn and/or practice algorithms. Inspired by ...
- Android提供的LruCache类简介
分类: Android开发 2013-02-06 15:26 26733人阅读 评论(10) 收藏 举报 package android.util; import import /** * A cac ...
- facebook海量图片存储系统与淘宝TFS系统比较
本篇论文的原文可谓通俗易懂.行云流水.结构清晰.图文并茂……正如作者所说的——"替换Facebook的图片存储系统就像高速公路上给汽车换轮子,我们无法去追求完美的设计……我们花费了很多的注意 ...
- ListView 点击某一项换背景图片
1. layout_search_list_item.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...
- 使用D3D渲染YUV视频数据
源代码下载 在PC机上,对于YUV格式的视频如YV12,YUY2等的显示方法,一般是采用DIRECTDRAW,使用显卡的OVERLAY表面显示.OVERLAY技术主要是为了解决在PC上播放VCD而在显 ...
- 转载RabbitMQ入门(6)--远程调用
远程过程调用(RPC) (使用Java客户端) 在指南的第二部分,我们学习了如何使用工作队列将耗时的任务分布到多个工作者中. 但是假如我们需要调用远端计算机的函数,等待结果呢?好吧,这又是另一个故事了 ...
- Banner 广告设计技巧及经验(转自UI中国)
经常听到banner这个词,但是banner是什么意思呢?引用百度知道的解释:banner可以作为网站页面的横幅广告,也可以作为游行活动时用的旗帜,还可以是报纸杂志上的大标题.Banner主要体现中心 ...
- [转]LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 原文地址:http://yacare.iteye.com/blog/2010049 很多伙伴在更新VS ...
- 使用七牛云存储----大家自己的图床[python]
##写博客什么的总得贴图吧,图床选来选去还是七牛吧.嗯,就是你了 [OSchaina 源码] 结合FastStone Capture 简直爽歪歪. FastStone Capture 自动保存图片到文 ...