CF1956C 题解
思路
这题我们可以枚举 ,均按 的排列填充第 行和第 列,最终可以填出类似这样的数组:
1 2 3 ... n
2 2 3 ... n
3 3 3 ... n
. .
. .
. .
n n n ... n
代码
# include <bits/stdc++.h>
using namespace std;
int t, n, sum;
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> t;
while (t --) {
cin >> n;
sum = 0;
for (int i = 1; i <= n; ++ i)
sum += i * (2 * i - 1);
cout << sum << ' ' << 2 * n << '\n';
for (int i = n; i; -- i) {
cout << "1 " << i << ' ';
for (int j = 1; j <= n; ++ j)
cout << j << ' ';
cout << '\n';
cout << "2 " << i << ' ';
for (int j = 1; j <= n; ++ j)
cout << j << ' ';
cout << '\n';
}
}
return 0;
}

浙公网安备 33010602011771号