2019ICPC(上海) - Spanning Tree Removal(构造)
生活随笔
收集整理的這篇文章主要介紹了
2019ICPC(上海) - Spanning Tree Removal(构造)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:給出一個 nnn 個點的無向完全圖,每次操作可以刪掉包含 nnn 個點的一棵生成樹中的所有邊,問最多可以刪幾次
題目分析:典中典之歐拉通路構造題,構造方式如下:
在選定某個點作為起點后,若將序號順時針規定為 {0,1,2,...,n?1}\{0,1,2,...,n-1\}{0,1,2,...,n?1},對于起點 ststst 來說的一條歐拉通路為 {st,st+1,st?2,st+3,st?4,st+5,...}\{st,st+1,st-2,st+3,st-4,st+5,...\}{st,st+1,st?2,st+3,st?4,st+5,...}
然后不難看出這個起點 ststst 可以順時針移動 ?n2?\lfloor\frac{n}{2}\rfloor?2n?? 個單位,并且這 ?n2?\lfloor\frac{n}{2}\rfloor?2n?? 個歐拉通路是沒有邊的交集的
代碼:
// Problem: Spanning Tree Removal // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/4370/D // Memory Limit: 1048576 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)// #pragma GCC optimize(2) // #pragma GCC optimize("Ofast","inline","-ffast-math") // #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef unsigned long long ull; template<typename T> inline void read(T &x) {T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f; } template<typename T> inline void write(T x) {if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0'); } const int inf=0x3f3f3f3f; const int N=1e6+100; int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);int w,kase=0;cin>>w;while(w--) {int n;read(n);printf("Case #%d: %d\n",++kase,n/2);for(int i=0;i<n/2;i++) {int sgn=1,pos=i,pre=-1;for(int j=1;j<n;j++) {pre=pos;pos=(pos+sgn*j+n)%n;sgn*=-1;printf("%d %d\n",pre+1,pos+1);}}}return 0; }總結
以上是生活随笔為你收集整理的2019ICPC(上海) - Spanning Tree Removal(构造)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021HDU多校6 - 7029 Me
- 下一篇: 2021HDU多校6 - 7028 De