Cells Arrangement

链接:https://www.luogu.com.cn/problem/CF1968E
题目:

有点像八皇后问题的条件
有一个重要的点就是明确上限:2*(N-1)所以应该是0~2n-2

思路就是选(1,1)和(1,2)然后剩下的点从(n,n)开始沿对角线往(1,1)放就行
代码:

#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;
typedef long long ll;
const int N = 1e3 + 10;
int a[N][N];
vector<int>dist;

int main()
{
	IOS;
	int t; cin >> t;
	while (t--)
	{
		memset(a, -1, sizeof(a));
		int n; cin >> n;
		if (n == 1)
		{
			cout << "1 1\n\n";
		}
		else if(n==2)
		{
			cout << "1 1\n1 2\n\n";
		}
		else
		{
			cout << "1 1\n1 2\n";
			for (int i = 0; i < n - 2; i++)cout << n - i << ' ' << n - i << '\n';
			cout << '\n';
		}
	}

	return 0;
}

posted on 2024-07-01 09:56  WHUStar  阅读(3)  评论(0编辑  收藏  举报