Target
SRM 633 · 2014-08-25 · by cgy4ever
SRM 633 · 2014-08-25 · by cgy4ever · Simple Search, Iteration
Problem Statement
Problem Statement
Here at [topcoder], we call a contestant a "target" if their rating is 3000 or more.
In the arena, the targets have a red icon with a small target on it.
Do you want to become a target as well?
Sure you do.
But before you get there, let's start with something easier: drawing a target.
The target you need to draw consists of nested squares. The innermost square is just a single '#' character. The larger squares use alternatingly the character ' ' (space) and the character '#'. Here is an example in which the side of the largest square is n = 5:
And here is an example for n = 9:
You will be given anint n.
Your method must return a String[] which contains a drawing of the target with side n.
More precisely, each element of the returned String[] must be one row of the drawing, in order.
Therefore, the returned String[] will consist of n elements, each with n characters.
(See the examples below for clarification.)
The value of n will be such that a target like the ones above can be drawn: 5, 9, 13, and so on. Formally, n will be of the form 4k+1, where k is a positive integer.
The target you need to draw consists of nested squares. The innermost square is just a single '#' character. The larger squares use alternatingly the character ' ' (space) and the character '#'. Here is an example in which the side of the largest square is n = 5:
##### # # # # # # # #####
And here is an example for n = 9:
######### # # # ##### # # # # # # # # # # # # # # # ##### # # # #########
You will be given an
The value of n will be such that a target like the ones above can be drawn: 5, 9, 13, and so on. Formally, n will be of the form 4k+1, where k is a positive integer.
Constraints
- n will be between 5 and 49, inclusive.
- n mod 4 will be 1.
Examples
0)
5
Returns: {"#####", "# #", "# # #", "# #", "#####" }
1)
9
Returns: {"#########", "# #", "# ##### #", "# # # #", "# # # # #", "# # # #", "# ##### #", "# #", "#########" }
2)
13
Returns: {"#############", "# #", "# ######### #", "# # # #", "# # ##### # #", "# # # # # #", "# # # # # # #", "# # # # # #", "# # ##### # #", "# # # #", "# ######### #", "# #", "#############" }
3)
17
Returns: {"#################", "# #", "# ############# #", "# # # #", "# # ######### # #", "# # # # # #", "# # # ##### # # #", "# # # # # # # #", "# # # # # # # # #", "# # # # # # # #", "# # # ##### # # #", "# # # # # #", "# # ######### # #", "# # # #", "# ############# #", "# #", "#################" }
4)
21
Returns: {"#####################", "# #", "# ################# #", "# # # #", "# # ############# # #", "# # # # # #", "# # # ######### # # #", "# # # # # # # #", "# # # # ##### # # # #", "# # # # # # # # # #", "# # # # # # # # # # #", "# # # # # # # # # #", "# # # # ##### # # # #", "# # # # # # # #", "# # # ######### # # #", "# # # # # #", "# # ############# # #", "# # # #", "# ################# #", "# #", "#####################" }
Submissions are judged against all 12 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Target with a public method vector<string> draw(int n) · 12 test cases · 2 s / 256 MB per case