UVA11387 - The 3-Regular Graph(推理)
题意:给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(推理)的更多相关文章
- cf#306D. Regular Bridge(图论,构图)
D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- cf550D Regular Bridge
Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal ...
- python数据结构与算法——图的基本实现及迭代器
本文参考自<复杂性思考>一书的第二章,并给出这一章节里我的习题解答. (这书不到120页纸,要卖50块!!,一开始以为很厚的样子,拿回来一看,尼玛.....代码很少,给点提示,然后让读者自 ...
- 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 ...
- 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 ...
- 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 ...
- 【cs224w】Lecture 5 - 谱聚类
Spectral Clustering 前面的课程说到了 community detection 并介绍了两种算法.这次来说说另外一类做社区聚类的算法,谱聚类.这种算法一般分为三个步骤 pre-pro ...
随机推荐
- noip2014总结
noip总结 经过七周的停课,我们终于迎来了期盼已久的noip考试.在这一次的noip考试中,我们经历了很多,也收获了很多.当然这一次考试中也有很多值得总结的地方,特写此总结. 这一次考试考得还不错, ...
- 学习linux之vi编辑器
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后 ...
- 并行任务task
http://msdn.microsoft.com/zh-cn/library/dd537609(v=vs.110).aspx http://www.cnblogs.com/yangecnu/p/So ...
- 【思路题】【多校第一场】【1001.OO’s Sequence】
题目大意: 给你一个序列A,f(l,r) 表示 在[l,r]中 的Ai 对于每一个数Aj 都有 Ai%Aj!=0 的数目( i!=j ) 卡了一段时间..... 题解 简单题 定义两个数组L[i ...
- 【高精度+DP】【HDU1223】 OrderCount
Order Count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- FFMPEG中最关键的结构体之间的关系
FFMPEG中结构体很多.最关键的结构体可以分成以下几类: a) 解协议(http,rtsp,rtmp,mms) AVIOContext,URLProtocol,URLContext主要 ...
- LINQ 基本子句之三 let
let子句,可以作为临时变量储存表达式的结果,但是let子句一旦初始化后无法再次进行更改. 1. static void Main(string[] args) { string[] names = ...
- Android开发中一些常见的问题解决方案
分享一下自己开发中遇到的一些常见问题及解决方案,方面以后快速开发少走弯路,也可以供大家一起学习. 1.开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listvie ...
- 沃通tomcat jks 安装配置
废话不多说上代码: <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtoc ...
- javascript 控制input
1.只允许输入数字 <input name="username" type="text" onkeyup="value=this.val ...