-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADAKING.cpp
99 lines (93 loc) · 1.96 KB
/
ADAKING.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//Problem link - https://www.codechef.com/JULY20B/problems/ADAKING
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define lli long long int
#define vi vector<int>
#define vll vector<lli>
#define pb push_back
#define all(v) v.begin(),v.end()
void solve(){
int n,i,j;
int prev_x, prev_y, last_x, last_y=-INT_MAX;
cin >> n;
char pos[8][8];
vector<vector<int>> v(8);
rep(i,8){
rep(j,8){
pos[i][j] = '.';
}
}
pos[0][0] = 'O';
if(n == 64){
goto here1;
}
prev_x = 0;
prev_y = 0;
rep(i,8){
prev_x = i;
rep(j,8){
prev_y = j;
if(n==0){
last_x = i;
//cout << i << endl;
goto here;
}
if(pow(prev_x-i,2)+pow(prev_y-j,2) <= 2){
//cout << i << " " << j << endl;
n--;
v[i].push_back(j);
}
}
//v.push_back(prev_y);
}
here:
rep(i,8){
int size = (int)v[i].size();
if(size!=0){
//cout << size << endl;
last_y = size;
if(v[i][size-1]+1 < 8){
pos[i][v[i][size-1]+1] = 'X';
}
}
}
//cout <<"last_x = " << last_x << endl;
if(last_y == 8){
f(i,last_x,8){
f(j,0,8){
pos[i][j] = 'X';
}
}
}else{
f(j,last_y,8){
pos[last_x][j] = 'X';
}
f(i,last_x+1,8){
rep(j,8){
pos[i][j] = 'X';
}
}
}
here1:
rep(i,8){
rep(j,8){
cout << pos[i][j];
}
cout << "\n";
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test_cases;
//test_cases = 1;
cin >> test_cases;
while(test_cases--){
solve();
}
return 0;
}