arc152d || Halftree
第一道场切的蓝构造!
思路
首先观察到每次操作其实都加了 -1 了。
我们考虑从
再进一步,令
令
下面给出我的构造方法:
设此刻还差
需要注意的是,因为一次操作实际上连了 +=2 而非 ++。
附 AC 记录
代码
#include<vector>
#include<iostream>
#define int long long
using namespace std;
const int N=2e5+5;
int t,n,k,tot,vu[N];
vector<int> num[N];
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>k;t=(n-1)/2;
if(n%2==0) return cout<<-1<<endl,0;
cout<<t<<endl;
tot=gcd(n,k);
for(int i=0;i<tot;i++){
int x=i;
while(!vu[x]){
num[i%tot].push_back(x);
vu[x]=1;x=(x+k)%n;
}
}
for(int i=1;i<tot;i++)
for(int j=1;j<n/tot;j+=2)
cout<<num[i-1][j-1]<<" "<<num[i][j]<<endl,t--;
int y=0;
while(y<tot){
for(int i=1;i<n/tot;i+=2)
cout<<num[y][i-1]<<" "<<num[y][i]<<endl,t--;
y+=n/tot-1;
}
for(int i=1;i<n/tot;i+=2){
if(!t) break;t--;
cout<<num[tot-1][i-1]<<" "<<num[tot-1][i]<<endl;
}
return 0;
}