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 + , INF = 1e9 + , mod = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int K, N, M;
void Build(int t) {
for(int i = t + ; i <= t + K - ; i++)
printf("%d %d\n", t, i);
for(int i = t + ; i <= t + K - ; i++)
for(int j = t + K ; j <= * K + t - ; j++)
printf("%d %d\n", i, j);
for(int i = K + t; i <= * K + t - ; i++)
if(((t & ) && (!(i & ))) || ((!(t & )) && (i & ))) printf("%d %d\n", i, i + );
}
main() {
K = read();
if(!(K & )) {puts("NO"); return ;}
puts("YES");
N = ( * (K - ) + ) * , M = N * K / ;
printf("%d %d\n", N, M);
printf("%d %d\n", , N / + );
Build();
Build(N / + );
return ;
}
/*
2 2 1
1 1
2 1 1
*/
cf550D. Regular Bridge(构造)的更多相关文章
- Codeforces Round #306 (Div. 2) D. Regular Bridge 构造
D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- cf550D Regular Bridge
Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal ...
- codeforces #550D Regular Bridge 构造
题目大意:给定k(1≤k≤100),要求构造一张简单无向连通图,使得存在一个桥,且每一个点的度数都为k k为偶数时无解 证明: 将这个图缩边双,能够得到一棵树 那么一定存在一个叶节点,仅仅连接一条桥边 ...
- Codeforces 550D —— Regular Bridge——————【构造】
Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 550 D. Regular Bridge
\(>Codeforces \space 550 D. Regular Bridge<\) 题目大意 :给出 \(k\) ,让你构造出一张点和边都不超过 \(10^6\) 的无向图,使得每 ...
- D. Regular Bridge 解析(思維、圖論)
Codeforce 550 D. Regular Bridge 解析(思維.圖論) 今天我們來看看CF550D 題目連結 題目 給你一個\(k\le100\),請構造出一個至少有一個Bridge的,每 ...
- cf#306D. Regular Bridge(图论,构图)
D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 「日常训练」Regular Bridge(Codeforces Round 306 Div.2 D)
题意与分析 图论基础+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #defi ...
- Codeforces Round #306 (Div. 2) ABCDE(构造)
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
随机推荐
- Windows 新增 Sublime Text3 右键快捷方式
Win10 创建 Sublime Text 3 右键快捷方式 Windows + R 输入 regedit 打开注册表编辑器: 依次找到 计算机\HKEY_CLASSES_ROOT\*\shell: ...
- 设计模式——原型模式(Prototype)
用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象.——DP UML类图 模式说明 如果把在一张纸上手写一篇简历的过程看成是类的实例化过程,那么通过原型模式创建对象的过程就是拿着这张纸到复印 ...
- GUI的最终选择 Tkinter(一):Tkinter最初体验
EasyGui就是一个简单的文字交互界面模块,从今天开始来开始学习Tkinter Tkinter是Python标准的Gui库,它实际是建立在Tk技术上的,Tk最初是为Tcl(一门工具名语言)所涉及的, ...
- 【ACM】子串和 - 贪心算法
子串和 时间限制:5000 ms | 内存限制:65535 KB 难度:3 描述 给定一整型数列{a1,a2...,an},找出连续非空子串{ax,ax+1,...,ay},使得该子序列的和最 ...
- HDU 5917 Instability ramsey定理
http://acm.hdu.edu.cn/showproblem.php?pid=5917 即世界上任意6个人中,总有3个人相互认识,或互相皆不认识. 所以子集 >= 6的一定是合法的. 然后 ...
- Linux Shell命令系列(2)
6. history命令 “history”命令就是历史记录.它显示了在终端中所执行过的所有命令的历史. 7. sudo命令 “sudo”(super user do)命令允许授权用户执行超级用户或者 ...
- /sbin/int的启动及后续进程的启动_3
转载自: http://www.ruanyifeng.com/blog/2013/08/linux_boot_process.html 半年前,我写了<计算机是如何启动的?>,探讨BIOS ...
- Java BIO
目录 BIO 字节流 OutputStream InputStream 字符流 Reader Writer 转换流 InputStreamReader OutputStreamWriter BIO I ...
- Unity3D C# 学习List数据类型的使用
List<T>类是ArrayList 类的泛型等效类. 该类使用大小可按需动态增加的数组实现 泛型的好处: 它为使用 c#语言编写面向对象程序增加了极大的效力和灵活性.不会强行对值类型进行 ...
- 解决Maven依赖下载不全的问题
背景描述 在日常学习过程中使用Maven构建SpringBoot+SpringCloud服务时,有时会使用非正式版的SpringBoot和SpringCloud(非正式版是指不是最终发布的版本,而是测 ...