forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLargestCircle.txt
202 lines (151 loc) · 5.82 KB
/
LargestCircle.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
PROBLEM STATEMENT
NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.
Given a regular square grid, with some number of squares marked, find
the largest circle you can draw on the grid that does not pass through
any of the marked squares. The circle must be centered on a grid point
(the corner of a square) and the radius must be an integer.
Return the radius of the circle.
The grid will be given as a vector <string>, with each character
representing a square. A '.' represents an empty square, and a '#'
represents a marked square.
The circle may intersect the corner of a marked square, but may not pass
through the interior. For example, given the grid:
{ "############",
"###......###",
"##.######.##",
"#.########.#",
"#.##..####.#",
"#.##..####.#",
"#.########.#",
"#.########.#",
"#.########.#",
"##.######.##",
"###......###",
"############" }
two circles can be drawn with radii 1 and 5, as shown below:
Therefore, your method should return 5.
Circles may not extend outside of the grid, and must have a radius of
at least 1. If no such circle exists, return 0.
DEFINITION
Class:LargestCircle
Method:radius
Parameters:vector <string>
Returns:int
Method signature:int radius(vector <string> grid)
CONSTRAINTS
-grid will contain between 1 and 50 elements, inclusive.
-Each element of grid will contain between 1 and 50 characters, inclusive.
-Each element of grid will contain the same number of characters.
-Each element of grid will contain only the characters '.' and '#'.
EXAMPLES
0)
{ "####",
"#..#",
"#..#",
"####" }
Returns: 1
Only one circle fits in this grid -- a circle of radius 1, in the center of the grid.
1)
{ "############",
"###......###",
"##.######.##",
"#.########.#",
"#.##..####.#",
"#.##..####.#",
"#.########.#",
"#.########.#",
"#.########.#",
"##.######.##",
"###......###",
"############" }
Returns: 5
This is the example from the problem statement.
2)
{ ".........." }
Returns: 0
The grid must be at least two squares wide and tall in order for any circles to fit.
3)
{ "#######",
"#######",
"#######",
"#######",
"#######" }
Returns: 0
4)
{ "#####.......",
"#####.......",
"#####.......",
"............",
"............",
"............",
"............",
"............",
"............",
"............" }
Returns: 4
A circle of radius 4 fits in this grid, as shown here:
5)
{ "#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.",
"...#...#...#...#...#...#...#...#...#...#...#...#..",
"#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.",
".#...#...#...#...#...#...#...#...#...#...#...#...#",
"#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.",
"...#...#...#...#...#...#...#...#...#...#...#...#..",
"#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.",
".#...#...#...#...#...#...#...#...#...#...#...#...#",
"#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.",
"...#...#...#...#...#...#...#...#...#...#...#...#.#",
"#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#." }
Returns: 0
6)
{ ".........................#........................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
"..................................................",
".................................................." }
Returns: 24