Skip to content

Commit b5c4471

Browse files
committed
srm 525 div 2 250
1 parent a1e97a5 commit b5c4471

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

RainyRoad.cpp

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <iostream>
2+
#include <sstream>
3+
#include <vector>
4+
#include <algorithm>
5+
#include <set>
6+
#include <map>
7+
using namespace std;
8+
vector<string> _road , __road;
9+
int n;
10+
11+
class RainyRoad {
12+
public:
13+
bool yes(int i, int j){
14+
if(__road[i][j] == 'X') return false;
15+
__road[i][j] = 'X';
16+
// cout<<i<<"\t"<<j<<endl;
17+
if(i > 1 || i < 0 || j >= n) return false;
18+
if(i == 0 && j == n-1) return true;
19+
if(_road[i][j] == 'W') return false;
20+
if(i == 0) return yes(i, j+1) || yes(i+1, j+1) || yes(i+1, j);
21+
if(i == 1) return yes(i, j+1) || yes(i-1, j) || yes(i-1, j+1);
22+
}
23+
24+
string isReachable(vector <string> road)
25+
{
26+
n = road[0].size();
27+
_road = road;
28+
__road = road;
29+
cout<<n<<endl;
30+
if(yes(0, 0)) return "YES";
31+
return "NO";
32+
}
33+
34+
// BEGIN CUT HERE
35+
public:
36+
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); if ((Case == -1) || (Case == 6)) test_case_6(); }
37+
private:
38+
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
39+
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
40+
void test_case_0() { string Arr0[] = {".W.."
41+
,"...."}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "YES"; verify_case(0, Arg1, isReachable(Arg0)); }
42+
void test_case_1() { string Arr0[] = {".W.."
43+
,"..W."}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "YES"; verify_case(1, Arg1, isReachable(Arg0)); }
44+
void test_case_2() { string Arr0[] = {".W..W.."
45+
,"...WWW."}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "NO"; verify_case(2, Arg1, isReachable(Arg0)); }
46+
void test_case_3() { string Arr0[] = {".."
47+
,"WW"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "YES"; verify_case(3, Arg1, isReachable(Arg0)); }
48+
void test_case_4() { string Arr0[] = {".WWWW."
49+
,"WWWWWW"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "NO"; verify_case(4, Arg1, isReachable(Arg0)); }
50+
void test_case_5() { string Arr0[] = {".W.W.W."
51+
,"W.W.W.W"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "YES"; verify_case(5, Arg1, isReachable(Arg0)); }
52+
void test_case_6() { string Arr0[] = {".............................................W."
53+
,".............................................W."}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "NO"; verify_case(6, Arg1, isReachable(Arg0)); }
54+
55+
// END CUT HERE
56+
57+
};
58+
59+
// BEGIN CUT HERE
60+
int main()
61+
{
62+
RainyRoad ___test;
63+
___test.run_test(-1);
64+
}
65+
// END CUT HERE

RainyRoad.txt

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
PROBLEM STATEMENT
2+
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.
3+
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.
4+
5+
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).
6+
7+
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.
8+
9+
Return the string "YES" if she can move to her destination without entering a tile which is filled with water. Otherwise, return "NO".
10+
11+
DEFINITION
12+
Class:RainyRoad
13+
Method:isReachable
14+
Parameters:vector <string>
15+
Returns:string
16+
Method signature:string isReachable(vector <string> road)
17+
18+
19+
NOTES
20+
-The constraints guarantee that the starting tile and the destination tile are never covered by water.
21+
22+
23+
CONSTRAINTS
24+
-road will contain exactly 2 elements.
25+
-Each elements of road will contain between 2 and 50 characters, inclusive.
26+
-All elements of road will contain the same number of characters.
27+
-Each character of road will be either '.' or 'W'.
28+
-The first character and the last character of 0-th element of road will be '.'.
29+
30+
31+
EXAMPLES
32+
33+
0)
34+
{".W.."
35+
,"...."}
36+
37+
Returns: "YES"
38+
39+
One of the possible ways is as follows. Here, 'F' is the tile occupied by Fox Ciel.
40+
41+
"FW.."
42+
"...."
43+
44+
".W.."
45+
"F..."
46+
47+
".W.."
48+
".F.."
49+
50+
".W.."
51+
"..F."
52+
53+
".W.F"
54+
"...."
55+
56+
57+
1)
58+
{".W.."
59+
,"..W."}
60+
61+
Returns: "YES"
62+
63+
64+
65+
2)
66+
{".W..W.."
67+
,"...WWW."}
68+
69+
Returns: "NO"
70+
71+
72+
73+
3)
74+
{".."
75+
,"WW"}
76+
77+
Returns: "YES"
78+
79+
80+
81+
4)
82+
{".WWWW."
83+
,"WWWWWW"}
84+
85+
Returns: "NO"
86+
87+
88+
89+
5)
90+
{".W.W.W."
91+
,"W.W.W.W"}
92+
93+
Returns: "YES"
94+
95+
96+
97+
6)
98+
{".............................................W."
99+
,".............................................W."}
100+
101+
Returns: "NO"
102+
103+

0 commit comments

Comments
 (0)