CF 1968 E. Cells Arrangement (*1600) 构造

CF 1968 E. Cells Arrangement (*1600) 构造

题目链接

题意

给你一个 n×n 的网格,请你在其中选择 n 个单元格,使得两两单元格之间曼哈顿距离种类数最大。

思路

一开始想到 (1,1)(n,n) 是必须要放的,这样我们得到了 02×(n1) 的距离。观察样例,猜测一定可以构造出 02×(n1) 之间的所有距离。那么我们可以在 (1,2) 放置一个。这样我们可以得到 12×(n1)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;
}
posted @   Showball  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示