CF1956C 题解

思路

这题我们可以枚举 i=n1i=n\sim1,均按 1n1\sim n 的排列填充第 ii 行和第 ii 列,最终可以填出类似这样的数组:

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;
}
posted @ 2024-04-18 21:19  Vitamin_B  阅读(5)  评论(0)    收藏  举报  来源