C. Nene's Magical Matrix

链接

https://codeforces.com/problemset/problem/1956/C

题目

思路

可以想到最终的答案一定是形如


就是外到内包裹的答案。

考虑如何构造这种。我们可以发现从外面一层一层“剥开”

可以看到蓝色部分是最早不变的,所以考虑如下的构造过程。

直到目标。所以由上述我们看出有点像“织毛衣”的过程,就是先纵改,再横改,从末尾开始到第一行/列。

细节见代码

代码

#define _CRT_SECURE_NO_WARNINGS 
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
#define IOS ios::sync_with_stdio(false), cin.tie(0) ,cout.tie(0)
using namespace std;
#define int long long 
signed main()
{
	IOS;
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		int ans = n * (n + 1) * (2 * n + 1) / 3 - (n + 1) * n / 2;
		cout << ans << ' ' << 2 * n << '\n';
		for (int i = 0; i < 2 * n; i++)
		{
			cout << i % 2 + 1 << ' ' << n - i / 2 << ' ';
			for (int j = 1; j <= n; j++)cout << j << ' ';
			cout << '\n';
		}
		
	}

	return 0;
}

posted on 2024-07-21 10:11  WHUStar  阅读(3)  评论(0编辑  收藏  举报