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 ...
随机推荐
- poj 1703(带权并查集)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31840 Accepted: ...
- Libgdx开发ios游戏
今天亲自尝试了LibGDX如何开发ios游戏, 必须条件: 1:mac操作系统,mac下必须安装Xcode 好像ios开发必须在mac操作系统下 2:mac下安装eclipse 3:eclip ...
- Gradle+Jetty实现静态资源的热部署
本文转自http://www.cnblogs.com/huang0925/p/3302487.html --------------------------------------- 通过Gradle ...
- Photoshop 批量处理图片
不论什么你想反复进行的操作都能够通过创建 Photoshop 批处理程序来完毕.比如.你想批量改变图片的大小,就能够通过下面操作来实现. 1.打开随意一张图片,在动作面板中,点击新建button 2. ...
- Python 练习 —— 2048
1. 引言 2048 这段时间火的不行啊,大家都纷纷仿造,"百家争鸣",于是出现了各种技术版本号:除了手机版本号,还有C语言版.Qt版.Web版.java版.C#版等,刚好我接触P ...
- winform —— 连接数据库SQL Server 2008
using System.Data.SqlClient;命名空间sqlconnection:数据连接类sqlcommand:数据库操作类sqldatareader:读取 using System; u ...
- 为net-snmp添加读readTimeTicks
function readTimeTicks(time){ if(time === 0) return ''; var d = 0, h = 0, m = 0, s = 0; d = parseInt ...
- Identity 验证,Authorize 特性
多类型角色访问 //[Authorize] //[Authorize(Roles = "User")] //[Authorize(Roles="Administrator ...
- 为 IIS 7.0 配置 <system.webServer>
Web.config 文件中的 system.webServer 节用于指定适用于 Web 应用程序的 IIS 7.0 设置.system.WebServer 是 configuration 节的子级 ...
- android 补间动画
android开发过程中,为了更好的展示应用程序,应用程序添加动画,能够很好地实现这个功能.如果动画中的图像变化有一定的规律,可以采用自动生成图像的方式来生成动画,例如图像的移动.旋转.缩放等.自动生 ...