forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRainyRoad.txt
103 lines (60 loc) · 2.11 KB
/
RainyRoad.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
PROBLEM STATEMENT
Fox Ciel is going to take a path to meet her friends. The path is tiled with 1x1 square tiles. It is N tiles long and 2 tiles wide. If we imagine that the path is going from the left to the right, we can view it as a rectangle with 2 rows and N columns of tiles.
The rows of the path are numbered 0 to 1 from top to bottom, and the columns of the path are numbered 0 to N-1 from left to right. Ciel starts at the tile in row 0, column 0. She has to reach the tile in row 0, column N-1.
In each step, Ciel can move to an adjacent tile. Two tiles are adjacent if they share at least one point (a side or a corner).
Because it rained yesterday, some tiles are covered by puddles of water. Ciel will not step on these tiles. You are given a vector <string> road. The j-th character of i-th element is 'W' if a tile at i-th row of j-th column is covered by water, and '.' otherwise.
Return the string "YES" if she can move to her destination without entering a tile which is filled with water. Otherwise, return "NO".
DEFINITION
Class:RainyRoad
Method:isReachable
Parameters:vector <string>
Returns:string
Method signature:string isReachable(vector <string> road)
NOTES
-The constraints guarantee that the starting tile and the destination tile are never covered by water.
CONSTRAINTS
-road will contain exactly 2 elements.
-Each elements of road will contain between 2 and 50 characters, inclusive.
-All elements of road will contain the same number of characters.
-Each character of road will be either '.' or 'W'.
-The first character and the last character of 0-th element of road will be '.'.
EXAMPLES
0)
{".W.."
,"...."}
Returns: "YES"
One of the possible ways is as follows. Here, 'F' is the tile occupied by Fox Ciel.
"FW.."
"...."
".W.."
"F..."
".W.."
".F.."
".W.."
"..F."
".W.F"
"...."
1)
{".W.."
,"..W."}
Returns: "YES"
2)
{".W..W.."
,"...WWW."}
Returns: "NO"
3)
{".."
,"WW"}
Returns: "YES"
4)
{".WWWW."
,"WWWWWW"}
Returns: "NO"
5)
{".W.W.W."
,"W.W.W.W"}
Returns: "YES"
6)
{".............................................W."
,".............................................W."}
Returns: "NO"