【构造】UVa 11387 The 3-Regular Graph
Description
输入n,构造一个n个点的无向图,使得每个点的度数都为3。不能有重边和自环,输出图或确定无解。
Solution
如果n为奇数,奇数*3=奇数,度数为奇,必无解。
考虑我们怎么构造一个图使得每个点度数为2?显然是直接连一个环。
再让他们度数为3,让点两两一连就行了。
秒之。
Code
注意n=2虽然是偶数但也无解。
#include<cstdio>
int main(){
int n;
while(scanf("%d",&n)==&&n){
if(n==||n%==){
printf("Impossible\n");
continue;
}
else{
printf("%d\n",n+n/);
for(int i=;i<n;i++)
printf("%d %d\n",i,i+);
printf("%d 1\n",n);
for(int i=;i<=n/;i++)
printf("%d %d\n",i,i+n/);
}
}
return ;
}
【构造】UVa 11387 The 3-Regular Graph的更多相关文章
- UVa 1479 (Treap 名次树) Graph and Queries
这题写起来真累.. 名次树就是多了一个附加信息记录以该节点为根的树的总结点的个数,由于BST的性质再根据这个附加信息,我们可以很容易找到这棵树中第k大的值是多少. 所以在这道题中用一棵名次树来维护一个 ...
- 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 ...
- Codeforces 550D —— Regular Bridge——————【构造】
Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #306 (Div. 2)A B C D 暴力 位/暴力 暴力 构造
A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- cf550D Regular Bridge
Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal ...
- cf#306D. Regular Bridge(图论,构图)
D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- python数据结构与算法——图的基本实现及迭代器
本文参考自<复杂性思考>一书的第二章,并给出这一章节里我的习题解答. (这书不到120页纸,要卖50块!!,一开始以为很厚的样子,拿回来一看,尼玛.....代码很少,给点提示,然后让读者自 ...
- Codeforces Round #306 (Div. 2) D
D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- paper: VG -- re-read
重点: 1.The constructed graph inherits several properties of the series in its structure. periodic se ...
随机推荐
- 浮点数据有损压缩算法 附完整C代码
在几年前的时候在做修图APP算法的时候, 曾经一度想过对3D Lut 预设数据进行压缩, 主要用于提升用户体验. 关于3d lut算法开源的资源也挺多的,就不多做科普了. 有兴趣的朋友,可以去查阅下f ...
- Java IO学习--(一)概述
在这一小节,我会试着给出Java IO(java.io)包下所有类的概述.更具体地说,我会根据类的用途对类进行分组.这个分组将会使你在未来的工作中,进行类的用途判定时,或者是为某个特定用途选择类时变得 ...
- css3属性(1)
text-transform语法: text-transform : none | capitalize| uppercase| lowercase 参数: none : 无转换发生 capitali ...
- [C#网络应用编程]2、对线程的管理
在System.Threading命名空间下,有一个Thread类,用于对线程进行管理,如创建线程.启动线程.终止线程.合并线程.让线程休眠等 Thread类 (假设Thread firTh = ne ...
- 对ajax基础的掌握随笔
原始的ajax,在第一个页面定义如下: function createAjax() { var xmlhttp; if (window.ActiveXObject) xmlhttp = new Act ...
- Vue、AngularJS 双向数据绑定解剖
数据与视图的绑定与同步,最终体现在对数据的读写处理过程中,也就是 Object.defineProperty() 定义的数据 set.get 函数中.Vue 中对于的函数为 defineReactiv ...
- Jmeter(二十七)_Beanshell保存响应内容到本地
利用Jmeter-BeanShell PostProcessor可以提取响应结果并保存到本地文件,这种操作在jmeter做爬虫时非常有用,可以帮助你迅速的获取想要的内容到本地文件! 1:在本地新建一个 ...
- python笔记:#011#循环
循环 目标 程序的三大流程 while 循环基本使用 break 和 continue while 循环嵌套 01. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 -- 从上向下,顺序执行 ...
- Flex 对Xml对象操作
一.读取.xml文件() import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; ...
- 使用清华源替代Ubuntu源
sudo nano /etc/apt/source.list 替换为如下文本 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main ...