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. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
随机推荐
- linux命令ln
创建软连接 ln -s 源文件 目标文件(指向源文件) ln -s /home/test/ /wang
- 判断是pc端登录还是移动端登录
java判断 https://blog.csdn.net/qq_32657581/article/details/71405838 https://zhidao.baidu.com/question/ ...
- 11 Lists
1 Lists 1.1 定义并访问Lists List list = new List[].也可以使用泛型.访问list中的元素,可以使用list.get(i) or list[i]. ...
- 04.Spring Ioc 容器 - 刷新
基本概念 Spring Ioc 容器被创建之后,接下来就是它的初始化过程了.该过程包含了配置.刷新两个步骤 . 刷新由 Spring 容器自己实现,具体发生在 ConfigurableApplicat ...
- calendar 类 用法
add()和roll()区别 一.Calendar 月份从 0-11,要表示8月,应该传入7 . 二.set() 会自动转换为合法的日期,如 set(1999,8,31) 表示的是1999-09-3 ...
- Shell笔试题3
1.查找当前目录中所有大于500M的文件,把这些文件名写到一个文本文件中,并统计其个数.find ./ -size +500M -type f | tee file_list | wc -l 2.在目 ...
- CI框架更新与删除
$this->load->database(); // $query=$this->db->get('t_repayments'); // $res ...
- iOS开发ReactiveCocoa学习笔记(一)
学习 RAC 我们首先要了解 RAC 都有哪些类 RACSignal RACSubject RACSequence RACMulticastConnection RACCommand 在学习的时候写了 ...
- linux下的tomcat开机自启动(亲测),更改静态ip
开机自启动Tomcat: 1.修改脚本文件rc.local:vim /etc/rc.d/rc.local 这个脚本是使用者自定的开机启动程序,可以在里面添加想在系统启动之后执行的脚本或者脚本执行命令 ...
- 自定义HashMap的键
用自定义的类型作为HashMap的key,必须同时重载hashCode()和equals(),才可以实现在HashMap中的查找自定义键. 例如自定义Point类: public class Poin ...