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. 智能指针weak_ptr解决循环依赖问题

    #include <iostream> #include <memory> class Woman; class Man{ private: std::weak_ptr< ...

  2. Dual Number

    http://ncatlab.org/nlab/show/dual+number http://mathworld.wolfram.com/DualNumber.html https://en.wik ...

  3. 记一次故障处理----主机异常关闭后mongodb二进制文件损坏

    今天,在某个演示环境中,我们的产品经历过整个机房断电后,出现了mongodb二进制文件损坏,以下是故障的分析记录过程: 1.在客户处支撑的同事发现整个机房断电再恢复后,3个mongodb复制集中,有1 ...

  4. 黄聪:如何为IIS增加svg和woff等字体格式的MIME

    现在字体图标已经渐渐代替了图片了,移动端用起来也很方便. 使用了字体文件来显示矢量的图标,为了能在IIS上正常显示图标,可以通过增加iis的MIME-TYPE来支持图标字体文件 下面就把IIS增加sv ...

  5. PBR实现

    我们的目标:UnityStandard 我一直作Unity开发,所以环境也就选择了Unity.目标也就是尽可能接近UnityStandard的效果,不过主要为了学习PBR,所以就只实现基本的PBR和法 ...

  6. [HTML5]HTML结构性元素(Structure)

    参考自:http://techbrood.com/h5b2a?p=html-structure 结构性元素用来组织文档的各个部分 为了让文档层次分明,我们可以把文档中的元素按其内容的作用进行组合,这就 ...

  7. xml保存基本信息

    public static string getXML(string nodeName) { string strReturn = ""; try { string fileNam ...

  8. java中Collection和Collections的区别

    1.Collection: 它是java集合类的一个通用接口,所有集合类都实现的它 2.Collections: 它是一个封装集合类常用工具方法的类,不能被示例化,只支持静态调用

  9. Java 反射 getDeclareFields getModifiers setAccessible(true)

    示例代码: public static Map<String, Object> dtoToMap(Object obj, String pre,            String las ...

  10. Nhibernate对应关系参数介绍

    一.多对一关联映配置介绍 <many-to-one name="PropertyName" 属性名 column="column_name" 数据库字段名 ...