题目链接

题意:给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. UGUI Silder

    来我们看看这个像温度计的控件, 比如音量面板声音大小的控制.它是一个组合型控件由多个Image 和一个Slider组合而成 它的核心是Slider组件实现的. 简单介绍下Slider组件的属性: Fi ...

  2. Unity 两张背景的切换平移

    两张背景图片向左移动,当屏幕看见的时候. 使用的是Unity自带的Sprite,当然也可以使用NGUI Sprite using UnityEngine; using System.Collectio ...

  3. QT_编程基础

    简单介绍 Qt是一个由奇趣科技开发的跨平台C++图形用户界面应用程序开发框架.它既能够开发GUI程式,也可用于开发非GUI程式,比方控制台工具和server. Qt是面向对象语言,易于扩展,而且同意组 ...

  4. WinForm RDLC SubReport Step by step

    最近在做的一个PO管理系统,因为要用到订单打印,没有用水晶报表,直接使用VS2010的Reporting.参考了网上的一些文章,但因为找到的数据是用于WebForm的,适配到WinForm有点区别,竟 ...

  5. 一.Linq to JSON是用来干什么的?

    Linq to JSON是用来操作JSON对象的.可以用于快速查询,修改和创建JSON对象.当JSON对象内容比较复杂,而我们仅仅需要其中的一小部分数据时,可以考虑使用Linq to JSON来读取和 ...

  6. Android 判断文件的类型

    import java.util.HashMap; import java.util.Iterator; /** * 判断文件的类型 */ public class MediaFileUtil { p ...

  7. OA、CRM、ERP之间的区别和联系是什么?

    我们假设你是某机械行业的销售,一切从今天你收到公司的邮件,去上海参加展会开始 因为 去展会 所有 首先 你打开 OA 登陆 填写出差申请表 送交主管审批 填表--审批--行政订票酒店 然后呢 你飞去上 ...

  8. php中Maximum execution time of 120 seconds exceeded时间超时错误解决方案

    1.修改php的配置文件,找到php.ini文件 max_execution_time = 120 ;//设置成你想要的值,单位是秒 2.使用ini_set()函数,使用这个函数来改变你的最大执行时间 ...

  9. 奇葩问题:spring+mybaits项目突然出现其中一些Mapper类找不到

    一.问题现象 1,No bean named 'bomManageMapper' found in org.springframework.beans.factory.support.DefaultL ...

  10. oracle全文检索笔记

    1.删除词法解析器 exec ctx_ddl.drop_preference('my_lexer'); 2.创建中文词法解析器 exec ctx_ddl.create_preference ('my_ ...