Codeforces 构造专题. C. Minimum Ties
原题链接
中等
作者:
captainDDL
,
2021-04-13 18:47:39
,
所有人可见
,
阅读 387
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N = 110;
int t, n;
int g[N][N];
int main() {
cin >> t;
while(t -- ) {
cin >> n;
memset(g, 0, sizeof g);
int rnd ;
if(n & 1) rnd = n / 2;
else rnd = n / 2 - 1;
for(int i = 1; i <= n; i ++ ) {
for(int j = 1; j <= rnd; j ++ ) {
int idx = (i - j + n) % n == 0 ? n : (i - j + n) % n;
g[idx][i] = 1, g[i][idx] = -1;
idx = (i + j) % n == 0 ? n : (i + j) % n;
g[i][idx] = 1, g[idx][i] = -1;
}
}
for(int i = 1; i <= n; i ++ ) {
for(int j = i + 1; j <= n; j ++ ) {
cout << g[i][j] << ' ';
}
}
cout << endl;
}
return 0;
}