题目链接

题意:给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. man/ls/clock/date/echo笔记

    login:    用户名:用户ID    认证机制:Authentication授权:Authorization审计:Audition (日志) prompt,命令提示符:命令:magic numb ...

  2. 【转】Android LCD(二):LCD常用接口原理篇

    关键词:android LCD TFT TTL(RGB)  LVDS  EDP MIPI  TTL-LVDS  TTL-EDP 平台信息:内核:linux2.6/linux3.0系统:android/ ...

  3. 银行综合储蓄业务系统,水平为学了一年C语言

    银行综合储蓄业务系统 #include <stdio.h> #include<string.h> int acccunt = 0; char name[10],pw[10]; ...

  4. linux下php扩展curl的安装

    方法一 安装cURL wget http://curl.haxx.se/download/curl-7.17.1.tar.gz tar -zxf curl-7.17.1.tar.gz ./config ...

  5. 虚拟化之KVM virsh常用命令篇

    1,查看运行的虚拟机 virsh list 2,查看所有的虚拟机(关闭和运行的虚拟机) virsh list --all 3,连接虚拟机 virsh console +域名(虚拟机的名称) 4,退出虚 ...

  6. ADT "Running Android Lint" has encountered a problem

    解决办法: Window--->Preferences----->Android--------> LInt Error Checking----->when saving f ...

  7. pl_sql 报ora-12154 无法解析指定的连接标识符的问题

    情况一:连接本地的没有问题,连接远程服务器的时候报以上错误.那么在本地客户端下的TNSNames.ora设置中配置你的远程服务器连接,本人的如下: //mestest是远程服务器名 //172.18. ...

  8. bootstrap插件小记

    1.模态框 除了通过data-toggle和data-target来控制模态弹出窗之外,Bootstrap框架针对模态弹出框还提供了其他自定义data-属性,来控制模态弹出窗.比如说:是否有灰色背景m ...

  9. C#抓取网页内容

    学习材料一 <C#抓取网页数据分析> 抓取Web网页数据分析 HttpWebRequest 和 HttpWebResponse 的应用

  10. JQ 操作样式,单选按钮跟复选框

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...