[TC] SRM 633 div2 250

本文指导您如何绘制一个由内向外嵌套的正方形组成的靶子图案,具体步骤涉及不同大小的正方形使用空格和井号字符交错排列。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 an int n. Your method must return a vector <string> which contains a drawing of the target with side n. 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 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.

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
{
        public:
        vector <string> draw(int n)
        {
        	int i,j;
        	VS ans;
            for (i=0;i<n;i++){
            	if (!(i&1)){
            		string s="";
            		int k=min(i/2,(n-1-i)/2);
            		for (j=1;j<=n;j++){
            			if (!(j&1) && ((j<=n/2 && j/2<=k) || (j>n/2) && (n-j+1)/2<=k)) s+=' ';
						else s+='#';
            		}
            		ans.push_back(s);
            	}
            	else{
            		string s="";
            		int k=min((i+1)/2,(n-i)/2);
            		for (j=1;j<=n;j++){
            			if ((j&1) && ((j<=n/2 && (j+1)/2<=k) || (j>n/2 && (n-j+2)/2<=k))) s+='#';
            			else s+=' ';
            		}
            		ans.push_back(s);
            	}
            }
            //int k=ans.size();
            //for (i=0;i<k;i++)
            //	cout<<ans[i]<<endl;
            return ans;
        }
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值