题目链接

题意:给n个点,问能否画出一个无向图。且每一个顶点连接3条边。假设能够的话输出连接的边。

思路:当添加一条边时,总的无向图的度数会添加2,所以度数之和n*2为偶数。当n为奇数时,度数之和为奇数,所以不存在。当n为偶数时才符合条件。注意特判n为2时的情况。

输出的话,就头尾相连,然后i与i+(n/2)相连。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int const MAXN = 105; int n; void outPut() {
printf("%d\n", n * 3 / 2);
for (int i = 1; i <= n; i++) {
int a = i;
int b = i + 1;
if (b > n)
b %= n;
printf("%d %d\n", a, b);
}
for (int i = 1; i <= n / 2; i++)
printf("%d %d\n", i, i + (n / 2));
} int main() {
while (scanf("%d", &n) && n) {
if (n < 4 || n % 2)
printf("Impossible\n");
else
outPut();
}
return 0;
}

UVA11387 - The 3-Regular Graph(推理)的更多相关文章

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

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

  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. cf550D Regular Bridge

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

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

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

  6. Codeforces Round #306 (Div. 2)

    A. Two Substrings You are given string s. Your task is to determine if the given string s contains t ...

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

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

  10. 【cs224w】Lecture 5 - 谱聚类

    Spectral Clustering 前面的课程说到了 community detection 并介绍了两种算法.这次来说说另外一类做社区聚类的算法,谱聚类.这种算法一般分为三个步骤 pre-pro ...

随机推荐

  1. Unity 制作RPG小地图

    效果图: 最近公司要制作小地图,搜索网上的文章没找到有什么小实例,=.=直接上步骤: 制作小地图步骤: 1. 人物头顶有一个面板呈现人物图标 2. 有一个摄像机在主角头顶!(Target Textur ...

  2. httpwatch 9.3怎么在ie 8上看不到

    首先,确认HttpWatch Basic加载项是否启动:打开IE,单击工具图标并选择管理加载项.确认HttpWatch Basic的状态是已启用,点击关闭.之后打开某个网页,在页面空白处右击选择Htt ...

  3. Extjs 6 MVC开发模式(二)

    1.Extjs MVC开发模式 在JS的开发过程中,大规模的JS脚本难以组织和维护,这一直是困扰前端开发人员的头等问题.Extjs为了解决这种问题,在Extjs4.x版本中引入了MVC开发模式,开始将 ...

  4. <audio> 标签简介

    定义和用法 <audio> 标签定义声音,比如音乐或其他音频流. 实例 一段简单的 HTML 5 音频: <audio src="someaudio.wav"&g ...

  5. PHP学习笔记六【方法-递归】

    <?php //递归 global $n;//定义全局变量 function abc($n) { if($n>2) { abc(--$n); } echo '$n='.$n.'<br ...

  6. sublime远程连接到linux主机

    sublime远程连接到linux主机 sublime远程连接到linux主机 微信开发,直接使用sublime的sftp功能修改wx_sample.php 1.为sublime安装安装包管理插件Pa ...

  7. Git commit template 模板设定

    多人协作开发一个项目时,版本控制工具是少不了的,git是linux 内核开发时引入的一个优秀代码管理工具,利用它能很好使团队协作完成一个项目.为了规范团队的代码提交,也方便出版本时的release n ...

  8. python运维开发(七)----面向对象(上)

    内容目录: 面向对象应用场景 类和对象的创建 类中的__init__构造方法 self理解 面向对象的三大特性:封装.继承.多态 概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装 ...

  9. zeromq-python使用

    安装参考saltstack编译安装.note 官方使用文档: http://zguide.zeromq.org/page:all 中文翻译文档: http://iyuan.iteye.com/blog ...

  10. FMDB用法

    iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.PlausibleDatabase.sqlitepers ...