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;
}
时间: 2024-10-29 19:10:14

UVA11387 - The 3-Regular Graph(推理)的相关文章

codeforce 550 D Regular Bridge

题意:建立一个连通图,它的所有点的度为k,且至少含有一个桥. 做法:先建立一个桥,再在桥两边建立两个度为k的连通图,通过这个桥连接在一起. 很显然k为偶数的时候无解. #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<v

cf550D Regular Bridge

Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components. Build a connected un

Codeforces550D:Regular Bridge

An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components. Build a connected undirected k-regu

python数据结构与算法——图的基本实现及迭代器

本文参考自<复杂性思考>一书的第二章,并给出这一章节里我的习题解答. (这书不到120页纸,要卖50块!!,一开始以为很厚的样子,拿回来一看,尼玛.....代码很少,给点提示,然后让读者自己思考怎么实现) 先定义顶点和边 1 class Vertex(object): 2 def __init__(self, label=''): 3 self.label = label 4 def __repr__(self): 5 return 'Vertex(%s)' % repr(self.label

Graph and Deep Learning

原文: https://devblogs.nvidia.com/parallelforall/intersection-large-scale-graph-analytics-deep-learning/ 摘要: 1)图在社交网络的数据分析中非常重要,而图变的越来越大,尽管内存容量也不断增加,in-memory的图处理仍然有局限,因此使用了一个基于Parallel Sliding Windows (PSW) 的分割技术,减小图处理对内存的需要. 2)图的并行化,基于edge的处理,比较容易负载均

Graph(2014辽宁ACM省赛)

问题 F: Graph 时间限制: 1 Sec  内存限制: 128 MB 提交: 30  解决: 5 [cid=1073&pid=5&langmask=0" style="color:rgb(26,92,200)">提交][id=2308" style="color:rgb(26,92,200)">状态][论坛] 题目描写叙述 Your task is to judge whether a regular polyg

TX2之多线程读取视频及深度学习推理

背景 一般在TX2上部署深度学习模型时,都是读取摄像头视频或传入视频文件进行推理,从视频中抽取帧进行目标检测等任务.对于大点的模型,推理的速度是赶不上摄像头或视频的帧率的,如果我们使用单线程进行处理,即读取一帧检测一帧,推理会堵塞视频的正常传输,表现出来就是摄像头视频有很大的延迟,如果是对实时性要求较高,这种延迟是难以接受的.因此,采用多线程的方法,将视频读取与深度学习推理放在两个线程里,互不影响,达到实时的效果. 实现方法 将摄像头的视频读取放入子线程,充当一个生产者的角色,将推理放入主线程,

A revolutionary architecture for building a distributed graph

转自:https://blog.apollographql.com/apollo-federation-f260cf525d21 What if you could access all of your organization’s data by typing a single GraphQL query, even if that data lived in separate places? Up until now, this goal has been difficult to achi

Graph machine learning 工具

OGB: Open Graph Benchmark https://ogb.stanford.edu/ https://github.com/snap-stanford/ogb OGB is a collection of benchmark datasets, data-loaders and evaluators for graph machine learning in PyTorch. Data-loaders are fully compatible with PyTorch Geom