cf550D. Regular Bridge(构造)
Posted zwfymqz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf550D. Regular Bridge(构造)相关的知识,希望对你有一定的参考价值。
题意
给出一个$k$,构造一个无向图,使得每个点的度数为$k$,且存在一个桥
Sol
神仙题
一篇写的非常好的博客:http://www.cnblogs.com/mangoyang/p/9302269.html
我简单的来说一下构造过程
首先$n$是偶数的时候无解
奇数的时候:我们拿出两个点作为桥
先构建一条桥边,对于两个端点分别做同样操作:
新建$k−1$个点,每个点向端点连边
再新建$k−1$个点,每个点向相邻的点连边
对于两层点形成的二分图,两两之间连边
/* */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<set> #include<queue> #include<cmath> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/hash_policy.hpp> #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define fi first #define se second //#define int long long #define LL long long #define ull unsigned long long #define rg register #define pt(x) printf("%d ", x); //#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++) //char buf[(1 << 22)], *p1 = buf, *p2 = buf; //char obuf[1<<24], *O = obuf; //void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + ‘0‘;} //#define OS *O++ = ‘ ‘; using namespace std; //using namespace __gnu_pbds; const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7; const double eps = 1e-9; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = getchar();} while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = getchar(); return x * f; } int K, N, M; void Build(int t) { for(int i = t + 1; i <= t + K - 1; i++) printf("%d %d ", t, i); for(int i = t + 1; i <= t + K - 1; i++) for(int j = t + K ; j <= 2 * K + t - 2; j++) printf("%d %d ", i, j); for(int i = K + t; i <= 2 * K + t - 2; i++) if(((t & 1) && (!(i & 1))) || ((!(t & 1)) && (i & 1))) printf("%d %d ", i, i + 1); } main() { K = read(); if(!(K & 1)) {puts("NO"); return 0;} puts("YES"); N = (2 * (K - 1) + 1) * 2, M = N * K / 2; printf("%d %d ", N, M); printf("%d %d ", 1, N / 2 + 1); Build(1); Build(N / 2 + 1); return 0; } /* 2 2 1 1 1 2 1 1 */
以上是关于cf550D. Regular Bridge(构造)的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces 550D Regular Bridge(构造)
「日常训练」Regular Bridge(Codeforces Round 306 Div.2 D)
AtCoder Regular Contest 103 Problem D Robot Arms (构造)
AtCoder Regular Contest 102D All Your Paths are Different Lengths 构造
AtCoder Regular Contest 102 D - All Your Paths are Different Lengths