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 isn
##### # # # # # # # ##### And here is an example for n = 9: ######### # # # ##### # # # # # # # # # # # # # # # ##### # # # #########
You will be given an int n. Your method must return a vector <string> which contains a drawing of the target with siden. More precisely, each element of the returned vector <string> must be one row of the drawing, in order. 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. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
- | n will be between 5 and 49, inclusive. | ||||||||||||
- | n mod 4 will be 1. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
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.
找规律画图啊……
class Target { private: bool pic[60][60]; void draw(int x,int y,int n) { if(n<1) return; for(int i=0;i<n;i++) { pic[x][y+i]=1; pic[x+n-1][y+i]=1; pic[x+i][y]=1; pic[x+i][y+n-1]=1; } draw(x+2,y+2,n-4); } public: vector <string> draw(int n) { memset(pic,0,sizeof(pic)); draw(0,0,n); vector<string>ans; for(int i=0;i<n;i++) { string s; for(int j=0;j<n;j++) s+=pic[i][j]?'#':' '; ans.push_back(s); } return ans; } };