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的更多相关文章

  1. UVa 1479 (Treap 名次树) Graph and Queries

    这题写起来真累.. 名次树就是多了一个附加信息记录以该节点为根的树的总结点的个数,由于BST的性质再根据这个附加信息,我们可以很容易找到这棵树中第k大的值是多少. 所以在这道题中用一棵名次树来维护一个 ...

  2. 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 ...

  3. Codeforces 550D —— Regular Bridge——————【构造】

     Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. 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 ...

  5. cf550D Regular Bridge

    Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal ...

  6. cf#306D. Regular Bridge(图论,构图)

    D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. python数据结构与算法——图的基本实现及迭代器

    本文参考自<复杂性思考>一书的第二章,并给出这一章节里我的习题解答. (这书不到120页纸,要卖50块!!,一开始以为很厚的样子,拿回来一看,尼玛.....代码很少,给点提示,然后让读者自 ...

  8. Codeforces Round #306 (Div. 2) D

    D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. paper: VG -- re-read

    重点:  1.The constructed graph inherits several properties of the series in its structure. periodic se ...

随机推荐

  1. PyQt IDE 环境搭建

    Eric的安装 1.按照目前pyqt5的要求安装了python3的最新版 2 pip3 install PyQt5 3. pip3 install QScintilla 4.download eric ...

  2. 保证你能看懂的KMP字符串匹配算法

    文章转载自一位大牛: 阮一峰原网址http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm ...

  3. AJAX的get和post请求原生编写方法

    var xhr=new XMLHttpRequest(); xhr.onreadystatechange=function(){ if(xhr.readyState===4){ if(xhr.stat ...

  4. 对JavaScript事件机制的一点理解

    JavaScript通过事件机制实现了异步操作,这种异步操作可以使CPU可以在IO任务的等待中被释放出来处理其他任务,等待IO结束再去处理这个任务.这个是一个基本的事件机制. 那么是不是说事件从监听到 ...

  5. 程序员DD 《Spring boot教程系列》补充

    最近在跟着程序员DD的Spring boot教程系列学习Spring boot,由于年代原因,Spring boot已经发生了一些变化,所以在这里进行一些补充. 补充的知识大多来自评论区,百度,Sta ...

  6. DOM4J熟知

    什么是解析xml 系统最终会从xml中读取数据. 读取的过程就是解析. CRUD ==> 增删改查 ==> create read update delete ==> 解析指的就是读 ...

  7. Python_语法和界面设计

    http://www.runoob.com/python/python-gui-tkinter.html  http://www.python-course.eu/python_tkinter.php

  8. Linux下MySQL的数据文件存放位置

    http://bbs.csdn.net/topics/390620630mysql> show variables like '%dir%';+------------------------- ...

  9. vi/vim操作

    vi/vim是unix/linux操作系统下的文本编辑器. 由于unix/linux万物届文件的特性,vi/vim可以编辑任何格式的文件. 下面是常见的知识点,仅供参考: 编辑方式:vi/vim + ...

  10. Linux共享库、静态库、动态库详解

    1. 介绍 使用GNU的工具我们如何在Linux下创建自己的程序函数库?一个“程序函数库”简单的说就是一个文件包含了一些编译好的代码和数据,这些编译好的代码和数据可以在事后供其他的程序使用.程序函数库 ...