URAL 2020. Traffic Jam in Flower Town(模拟)
来源:互联网 发布:中国电信云计算公司 编辑:程序博客网 时间:2024/06/01 08:39
2020. Traffic Jam in Flower Town
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
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.
Samples
RLFFF
4
LL
1
Notes
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.
题意:(download下网友)有两列摩托车从十字路口经过,一列为从南向北行驶,一列从北向南行驶,且南北向路是双行线,而东西线路是单行线,要求的是两列摩托车经过十字路口的最短时间。
题解:
小模拟。。。开始少了上面加红的一种情况了。。。
我的代码!
#include <bits/stdc++.h>using namespace std;char ch1[1000+10],ch2[1000+10];int main (){ int n; while(~scanf("%s%s",ch1,ch2)) { int pnt1=0,pnt2=0; int len1=strlen(ch1),len2=strlen(ch2); int sum=0; while(pnt1!=len1&&pnt2!=len2){ if(ch1[pnt1]=='R'){ pnt1++,pnt2++; }else if(ch1[pnt1]=='L'&&(ch2[pnt2]=='R'||ch2[pnt2]=='L')){ pnt1++,pnt2++; }else if(ch1[pnt1]=='L'&&ch2[pnt2]=='F'){ pnt2++; }else if(ch1[pnt1]=='F'&&(ch2[pnt2]=='R'||ch2[pnt2]=='F')){ pnt1++,pnt2++; }else if(ch1[pnt1]=='F'&&ch2[pnt2]=='L'){ pnt1++; } sum++; } while(pnt1!=len1) sum++,pnt1++; while(pnt2!=len2) sum++,pnt2++; printf("%d\n",sum); } return 0;}为什么我感觉自己A掉的都是水题,是自己太水么。。。
0 0
- URAL 2020. Traffic Jam in Flower Town(模拟)
- URAL 2020. Traffic Jam in Flower Town
- URAL2020 Traffic Jam in Flower Town (模拟)
- poj1817 Traffic Jam
- Traffic Jam UVA
- (noip 模拟 flower 种花)<贪心+后悔>
- 【codechef】Traffic jam for N5
- LA 4082 Traffic Jam (分块)
- 搜索 HOJ 1838 Traffic Jam
- POJ 1817 Traffic Jam 笔记
- Zball in Tina Town
- Zball in Tina Town
- hdu5391Zball in Tina Town
- noip2006 JAM计数法 (模拟)
- Zball in Tina Town(杭电5391)
- hdu 5392 Infoplane in Tina Town(快速幂)
- hdu5391 Zball in Tina Town(素数筛法)
- HDOJ-5391 Zball in Tina Town(数学)
- Effective Object_C 2.0 编写高质量ios与OS X代码的52个有效方法之一
- csdn的第一篇博客
- 程序性能优化之map影响
- java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L
- IntelliJ IDEA提示找不到符号,或程序包不存在
- URAL 2020. Traffic Jam in Flower Town(模拟)
- IE9及其以下input输入框数字问题
- 2017第五届国际服务机器人核心技术及渠道应用大会即将于5月在京举行!
- 动态显示和隐藏状态栏
- springMVC框架网页下载功能实现
- Spring Boot集成Swagger2并替换默认的UI
- Linux运维笔记-文档总结-永久更改文件SELINUX安全上下文和管理SELINUX布尔值
- json解析
- 微信小程序『侧边栏滑动』特效