Problem Statement

    

The purpose of a roundabout is to control the flow of traffic at a busy intersection. A roundabout has 4 entry points: from the North, East, South and West; and 4 exit points at the same locations (see Example 0 for a diagram).

Cars can enter, leave or move one position on the roundabout. Each of those events requires one second. All the events can take place simultaneously. So if there are two cars on the roundabout, one behind the other, then they can both move during the next second. A car decides whether to enter the roundabout based on its knowledge from the previous second. A car will always enter if it has the right to do so.

A car has the right to enter only if there are no cars to its immediate left (either on the roundabout or waiting to get on the roundabout) and it is the first car in line at the entry point (Example 1 demonstrates this). A special case occurs if there is a car at each of the 4 entry points. In this case, the car from the North will wait until there are no cars to its left on the roundabout and then will be the first to enter.

Once the car is on the roundabout, it moves counter-clockwise until it exits the roundabout. There are 4 positions on the roundabout. So for example, it would take 1 second to enter the roundabout, 2 seconds to complete half a lap and another 1 second to exit the roundabout.

Each parameter of the input is a second by second account of cars coming from that direction with their intended exit locations. Intended exit locations will be N (North), E (East), S (South) and W (West). A '-' means that no car arrived during that second at the given entry point. Thus, for example, character i of north represents the direction in which a car (if there is one) arriving from the north at time i will leave the roundabout. So, at time i, this car will be added to the end of the line at the north entry point to the roundabout. Cars will not be allowed to exit the roundabout at the point of their entry.

Given the lists of cars coming from the 4 directions, return the total time required for all cars to leave the roundabout.

Definition

    
Class: Roundabout
Method: clearUpTime
Parameters: String, String, String, String
Returns: int
Method signature: int clearUpTime(String north, String east, String south, String west)
(be sure your method is public)

Limits

    
Time limit (s): 2.000
Memory limit (MB): 64

Constraints

- north, east, south and west will contain between 0 and 50 characters inclusive.
- north, east, south and west must only contain 'N', 'W', 'S', 'E' and '-' characters.
- north will NOT contain the character 'N'.
- east will NOT contain the character 'E'.
- south will NOT contain the character 'S'.
- west will NOT contain the character 'W'.

Examples

0)  
    
"--"
"--"
"WE"
"-S"
Returns: 6
Note for plugin users: this example contains an image. Please view the problem in the applet to see the image.

At
the start, a car approaches the roundabout from the
South. At time = 1, the car going West enters the
roundabout, another car approaches from the South and
another one from the West. At time = 2, the car going
West moves one position, the car going East must give
way, the car going South enters the roundabout. At time
= 3, the car going West moves one position, the car
going East must still give way, the car going South
moves one position. At time = 4, the car going West
moves one position, the car going South exits the
roundabout, the car going East enters the roundabout. At
time = 5, the car going West exits the roundabout, the
car going East moves one position. At time = 6, the car
going East exits the roundabout. The method should
return 6.
1)  
    
"WWW"
"NNN"
"---"
"---"
Returns: 9
All the cars from the North must wait until the cars from the East exit the roundabout. Only then can they enter the roundabout.
2)  
    
"SSS"
"WW-"
"N"
"S------"
Returns: 13
 
3)  
    
"SSS-"
"--W---W"
"WE"
"-S"
Returns: 14
 
4)  
    
"E"
"-N"
"W"
"-S"
Returns: 5
 
5)  
    
""
""
""
""
Returns: 0
 
6)  
    
"W"
""
"--E"
""
Returns: 6
Note: At time = 3, the car from the South does not enter the roundabout, because it has already decided not to enter, based on its knowledge from the previous second. Thus it enters at time = 4.
7)  
    
"ES"
"N"
"E"
""
Returns: 9
 
8)  
    
"E"
"SN"
"-N"
"S-E"
Returns: 12
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

SRM 146 DIV1 800的更多相关文章

  1. SRM 146 DIV1 600

    Problem Statement      Masterbrain is a two player board game in which one player decides on a secre ...

  2. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  3. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  4. 图论 SRM 674 Div1 VampireTree 250

    Problem Statement      You are a genealogist specializing in family trees of vampires. Vampire famil ...

  5. SRM 583 DIV1

    A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...

  6. SRM 590 DIV1

    转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlov ...

  7. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  8. 状态压缩DP SRM 667 Div1 OrderOfOperations 250

    Problem Statement      Cat Noku has just finished writing his first computer program. Noku's compute ...

  9. 数学 SRM 690 Div1 WolfCardGame 300

    Problem Statement      Wolf Sothe and Cat Snuke are playing a card game. The game is played with exa ...

随机推荐

  1. maven 记录

    1. Can't find parent:  工程中的pom.xml中定义的”project -> version”或者”parent project -> version”设置的不对导致 ...

  2. C#动手实践:Kinect V2 开发(1):初步了解及环境搭建

    该分享使用的是Kinect 二代,C#做为编程语言,请知悉 Kinect是微软在2009年6月2日的E3游戏展上,正式公布的XBOX360体感周边外设.它是一种3D体感摄影机,同时它导入了即时动态捕捉 ...

  3. Java lamda Stream

    Intermediate:一个流可以后面跟随零个或多个 intermediate 操作.其目的主要是打开流,做出某种程度的数据映射/过滤,然后返回一个新的流,交给下一个操作使用.这类操作都是惰性化的( ...

  4. ses_cations 值顺序

    16个位置的字符所代表的操作依次如下: 1. ALTER 2. AUDIT 3.COMMENT 4.DELETE 5.GRANT 6.INDEX 7.INSERT 8.LOCK 9.RENAME 10 ...

  5. string相关总结

    一 <string> 1 string类常见成员函数 (1)属性相关 s.empty()   s为空时返回true,否则返回false s.size()      返回s中字符的个数,不包 ...

  6. oracle kill session

    kill session 是DBA经常碰到的事情之一.如果kill 掉了不该kill 的session,则具有破坏性,因此尽可能的避免这样的错误发生.同时也应当注意,如果kill 的session属于 ...

  7. 03-c#入门(简易存款利息计算器v1.0)

    本想把练习题做了的结果放上来,不过发现附录是有答案的,就算了吧,自己做了没问题就行了哈.之前提到过,要是有朋友有想法,需要做小工具我可以帮忙实现,不过貌似大家都很忙.SO,自己学完第4章后,决定做一个 ...

  8. Url路径重写的原理

    ASP.net的地址重写(URLRewriter)实现原理及代码示例 吴剑 2007-01-01 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian/ 概述 访问 ...

  9. C#小程序飞行棋地图绘制

    1. 初始化地图,在绘制时可先将地图进行初始化,用数组来存储关卡的位置,然后利用循环给地图中 关卡所在处赋予代表关卡的值. 关键代码如下 /// <summary> /// 初始化游戏地图 ...

  10. sublimetext 3 set

    from https://segmentfault.com/a/1190000002596724{ "font_size": 21, "highlight_line&qu ...