D Spanning Tree Removal
题意:给定一个n的完全图,每次操作是从图中移除一棵生成树的所有边,问最多能进行多少次这样的操作?输出操作次数和每次移除的生成树的边。
思路:边n*(n-1)/2,每颗生成树为n-1条边,所以猜测n/2条边,构造方法的话也比较巧;
所有点顺时针编号(0~n-1)
以x为起点,连接的点y为顺时针+1
从y找下一个点,连接的点z为逆时针-2
然后形成一个z字。
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
int t;
cin >> t;
int T = 0;
while(t--){
int n;cin >> n;
printf("Case #%d: %d\n",++T,n/2);
for(int i = 1;i <= n/2;i++){
int f = 1;
int u = i - 1;
for(int j = 1;j < n;j++){
int v = (u + j*f + n)%n;
printf("%d %d\n",u+1,v+1);
f *= -1;
u = v;
}
}
}
return 0;
}