Skip to content

Commit a11bf59

Browse files
committed
srm 633 div 2 250
1 parent 0dd6bf9 commit a11bf59

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

Target.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <iostream>
2+
#include <sstream>
3+
#include <vector>
4+
#include <algorithm>
5+
#include <set>
6+
#include <map>
7+
#include <queue>
8+
#include <cstring>
9+
#include <climits>
10+
using namespace std;
11+
typedef pair<int,int> pi;
12+
typedef vector<int> vi;
13+
typedef vector<vi> vvi;
14+
typedef vector<string> vs;
15+
typedef vector<vs> vvs;
16+
17+
class Target {
18+
public:
19+
vector <string> draw(int n)
20+
{
21+
string s(n, ' ');
22+
vector<string> A(n, s);
23+
int k = 1;
24+
int n1 = n/2;
25+
A[n1][n1] = '#';
26+
while(k < n){
27+
int k1 = n1-k/2-1, k2 = n1+k/2+1;
28+
for(int kk = k1; kk <= k2; kk++){
29+
A[kk][k1] = A[kk][k2] = A[k1][kk] = A[k2][kk] = ' ';
30+
}
31+
k1--; k2++;
32+
for(int kk = k1; kk <= k2; kk++){
33+
A[kk][k1] = A[kk][k2] = A[k1][kk] = A[k2][kk] = '#';
34+
}
35+
k += 4;
36+
}
37+
return A;
38+
}
39+
40+
// BEGIN CUT HERE
41+
public:
42+
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); }
43+
private:
44+
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
45+
void verify_case(int Case, const vector <string> &Expected, const vector <string> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } }
46+
void test_case_0() { int Arg0 = 5; string Arr1[] = {"#####", "# #", "# # #", "# #", "#####" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(0, Arg1, draw(Arg0)); }
47+
void test_case_1() { int Arg0 = 9; string Arr1[] = {"#########", "# #", "# ##### #", "# # # #", "# # # # #", "# # # #", "# ##### #", "# #", "#########" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(1, Arg1, draw(Arg0)); }
48+
void test_case_2() { int Arg0 = 13; string Arr1[] = {"#############", "# #", "# ######### #", "# # # #", "# # ##### # #", "# # # # # #", "# # # # # # #", "# # # # # #", "# # ##### # #", "# # # #", "# ######### #", "# #", "#############" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(2, Arg1, draw(Arg0)); }
49+
void test_case_3() { int Arg0 = 17; string Arr1[] = {"#################", "# #", "# ############# #", "# # # #", "# # ######### # #", "# # # # # #", "# # # ##### # # #", "# # # # # # # #", "# # # # # # # # #", "# # # # # # # #", "# # # ##### # # #", "# # # # # #", "# # ######### # #", "# # # #", "# ############# #", "# #", "#################" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(3, Arg1, draw(Arg0)); }
50+
51+
// END CUT HERE
52+
53+
};
54+
55+
// BEGIN CUT HERE
56+
int main(){
57+
58+
Target ___test;
59+
___test.run_test(-1);
60+
61+
}
62+
// END CUT HERE

Target.txt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
PROBLEM STATEMENT
2+
Here at [topcoder], we call a contestant a "target" if their rating is 3000 or more.
3+
In the arena, the targets have a red icon with a small target on it.
4+
Do you want to become a target as well?
5+
Sure you do.
6+
But before you get there, let's start with something easier: drawing a target.
7+
8+
9+
10+
The target you need to draw consists of nested squares.
11+
The innermost square is just a single '#' character.
12+
The larger squares use alternatingly the character ' ' (space) and the character '#'.
13+
Here is an example in which the side of the largest square is n = 5:
14+
15+
16+
17+
18+
#####
19+
# #
20+
# # #
21+
# #
22+
#####
23+
24+
25+
26+
And here is an example for n = 9:
27+
28+
29+
30+
#########
31+
# #
32+
# ##### #
33+
# # # #
34+
# # # # #
35+
# # # #
36+
# ##### #
37+
# #
38+
#########
39+
40+
41+
42+
43+
You will be given an int n.
44+
Your method must return a vector <string> which contains a drawing of the target with side n.
45+
More precisely, each element of the returned vector <string> must be one row of the drawing, in order.
46+
Therefore, the returned vector <string> will consist of n elements, each with n characters.
47+
(See the examples below for clarification.)
48+
49+
50+
51+
The value of n will be such that a target like the ones above can be drawn: 5, 9, 13, and so on.
52+
Formally, n will be of the form 4k+1, where k is a positive integer.
53+
54+
DEFINITION
55+
Class:Target
56+
Method:draw
57+
Parameters:int
58+
Returns:vector <string>
59+
Method signature:vector <string> draw(int n)
60+
61+
62+
CONSTRAINTS
63+
-n will be between 5 and 49, inclusive.
64+
-n mod 4 will be 1.
65+
66+
67+
EXAMPLES
68+
69+
0)
70+
5
71+
72+
Returns: {"#####", "# #", "# # #", "# #", "#####" }
73+
74+
75+
76+
1)
77+
9
78+
79+
Returns: {"#########", "# #", "# ##### #", "# # # #", "# # # # #", "# # # #", "# ##### #", "# #", "#########" }
80+
81+
82+
83+
2)
84+
13
85+
86+
Returns: {"#############", "# #", "# ######### #", "# # # #", "# # ##### # #", "# # # # # #", "# # # # # # #", "# # # # # #", "# # ##### # #", "# # # #", "# ######### #", "# #", "#############" }
87+
88+
89+
90+
3)
91+
17
92+
93+
Returns: {"#################", "# #", "# ############# #", "# # # #", "# # ######### # #", "# # # # # #", "# # # ##### # # #", "# # # # # # # #", "# # # # # # # # #", "# # # # # # # #", "# # # ##### # # #", "# # # # # #", "# # ######### # #", "# # # #", "# ############# #", "# #", "#################" }
94+
95+

0 commit comments

Comments
 (0)