跳到正文

题解

CF1956C 题解

Vitamin_B约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年4月18日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟
题目
CF1956C

版本

  1. v1当前

思路

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

代码
1 2 3 ... n
2 2 3 ... n
3 3 3 ... n
.    .
.     .
.      .
n n n ... n

代码

C++
# 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;
}
原文