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. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
随机推荐
- MD5WLBUtil
import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; import j ...
- Hive_hdfs csv导入hive demo
1 create csv file.student.csv 4,Rose,M,78,77,76 5,Mike,F,99,98,98 2 put it to hdfs. # hdfs dfs -put ...
- 04.Spring Ioc 容器 - 刷新
基本概念 Spring Ioc 容器被创建之后,接下来就是它的初始化过程了.该过程包含了配置.刷新两个步骤 . 刷新由 Spring 容器自己实现,具体发生在 ConfigurableApplicat ...
- Asp.NetCore 2.2 WebApi 发布到IIS步骤及错误处理
一.创建一个Asp.NetCore WebApi 程序(话不多说) 二.发布 三.配置IIS 程序池中选中网站的程序池 ——基本设置 浏览网站——浏览器 域名后面输入api/values 四.错误处理 ...
- CSS细节
写起这篇文章,是因为阅读张鑫旭到的一篇文章<CSS的学习瓶颈>,里面提到了要重视CSS的细节和实现机制.确实:有必要掌握一些关于CSS方面的细节,而不是遇到任何页面,都添加css.rese ...
- SharePoint 2010开发方面的课堂中整理有关问题
SharePoint 2010开发方面的课堂中整理有关问题 这是我这几天在做一个SharePoint开发的课程的时候,大家提出的一些问题,及我的解答,分享给更多的朋友参考一下 这个文档,也可以在这里下 ...
- UVALive 4261——Trip Planning——————【dp+打印路径】
Trip Planning Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Stat ...
- over partition by与group by
over partition by与group by 的区别 http://www.cnblogs.com/scottpei/archive/2012/02/16/2353718.html 今天看到一 ...
- [Java][Liferay] 解决Liferay ext项目deploy的问题
Liferay ext project在install war包之后需要重启服务器,重启服务器中会执行ExtHotDeployListener中的逻辑,这里有一个坑,如果是第二次以后install e ...
- C 碎片五 数组
构造类型数据是有基本类型数据按照一定规则组成的.数组,结构体,共用体都属于构造类型的数据.数组是有序数据的集合,C语言数组中的每一个元素都属于同一个数据类型,用数组名和下标来唯一确定数组中的元素. 一 ...