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 ...
随机推荐
- Team Formation(思维)
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contes ...
- wpf Visibility 动画
XAML实现: [xhtml] view plaincopy <Border Height="100" Width="80" CornerRadius=& ...
- 【二分图最大匹配】【HDU2063】过山车
[科普]什么是BestCoder?如何参加? 过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- Jq自定义动画
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 计算UILabel的高度
//计算文本高度 NSString *lltxt =[[NSString alloc]initWithFormat:@"浏览:%@",[strJson objectForKey:@ ...
- EntityFramework sum嵌套
一个查询中 用到了 sum , 可是返回结果的小数有很多位 , 都不准确了..类似js中的小数运算一样...不太熟悉C#,不知道这问题是因为double的关系 , 还是因为代码写的问题 , 通过 sq ...
- java 成神之路
一.基础篇 1.1 JVM 1.1.1. Java内存模型,Java内存管理,Java堆和栈,垃圾回收 http://www.jcp.org/en/jsr/detail?id=133 http://i ...
- ubuntu安装jira步骤
背景:前些日子在原来的一台云主机上已经部署了一个jira系统,使用一段时间后发现jira占用很多的系统资源,导致主机上的其他服务无法正常工作,于是老大新注册了一个云主机专门用于运行jira,可见公司对 ...
- [ofbiz]screen中应用form和ftl,控制页面元素属性
可以在screen中定义form与ftl两个文件,ftl中可以使用js控制form中的页面元素属性. 控制元素是否可编辑: $("#oaDataReport_budget&qu ...
- 深入研究B树索引(一)
摘要:本文对B树索引的结构.内部管理等方面做了一个全面的介绍.同时深入探讨了一些与B树索引有关的广为流传的说法,比如删除记录对索引的影响,定期重建索引能解决许多性能问题等. 1.B树索引的相关概念 索 ...