现在的位置: 首页 > 综合 > 正文

SRM 633 DIV2 A

2019年11月09日 ⁄ 综合 ⁄ 共 2340字 ⁄ 字号 评论关闭
文章目录

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
= 5:

#####
#   #
# # #
#   #
#####

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.
Therefore, the returned vector <string> will consist ofn 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.

Definition

 
Class: Target
Method: draw
Parameters: int
Returns: vector <string>
Method signature: vector <string> draw(int n)
(be sure your method is public)

Limits

 
Time limit (s): 2.000
Memory limit (MB): 256

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: 
{"#################",
 "#               #",
 "# ############# #",
 "# #           # #",
 "# # ######### # #",
 "# # #       # # #",
 "# # # ##### # # #",
 "# # # #   # # # #",
 "# # # # # # # # #",
 "# # # #   # # # #",
 "# # # ##### # # #",
 "# # #       # # #",
 "# # ######### # #",
 "# #           # #",
 "# ############# #",
 "#               #",
 "#################" }

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;
		}
};

抱歉!评论已关闭.