CF 1968 E. Cells Arrangement (*1600) 构造
CF 1968 E. Cells Arrangement (*1600) 构造
题意:
给你一个 \(n\times n\) 的网格,请你在其中选择 \(n\) 个单元格,使得两两单元格之间曼哈顿距离种类数最大。
思路:
一开始想到 \((1,1)\) 和 \((n,n)\) 是必须要放的,这样我们得到了 \(0\) 和 \(2\times(n-1)\) 的距离。观察样例,猜测一定可以构造出 \(0-2\times (n-1)\) 之间的所有距离。那么我们可以在 \((1,2)\) 放置一个。这样我们可以得到 \(1\) 和 \(2\times(n-1) -1\) 的距离。对于剩下的,我们可以考虑全部放到对角线上,这样我们发现两两之间距离为 \(2\),所有偶数都可以凑出来,由于 \((1,2)\) 的存在,所有奇数也都可以凑出来。当然也可以通过归纳法证明。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define all(u) u.begin(), u.end()
#define endl '\n'
#define debug(x) cout<<#x<<":"<<x<<endl;
typedef pair<int, int> PII;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10, M = 105;
const int mod = 1e9 + 7;
const int cases = 1;
void Showball(){
int n;
cin>>n;
cout<<"1 1\n1 2\n";
for(int i=3;i<=n;i++){
cout<<i<<" "<<i<<endl;
}
cout<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T=1;
if(cases) cin>>T;
while(T--)
Showball();
return 0;
}