zoukankan      html  css  js  c++  java
  • 【构造】UVa 11387 The 3-Regular Graph

    Description

    输入n,构造一个n个点的无向图,使得每个点的度数都为3。不能有重边和自环,输出图或确定无解。

    Solution

    如果n为奇数,奇数*3=奇数,度数为奇,必无解。

    考虑我们怎么构造一个图使得每个点度数为2?显然是直接连一个环。

    再让他们度数为3,让点两两一连就行了。

    秒之。

    Code

    注意n=2虽然是偶数但也无解。

     1 #include<cstdio>
     2 int main(){
     3     int n;
     4     while(scanf("%d",&n)==1&&n){
     5         if(n==2||n%2==1){
     6             printf("Impossible
    ");
     7             continue;
     8         }
     9         else{
    10             printf("%d
    ",n+n/2);
    11             for(int i=1;i<n;i++)
    12                 printf("%d %d
    ",i,i+1);
    13             printf("%d 1
    ",n);
    14             for(int i=1;i<=n/2;i++)
    15                 printf("%d %d
    ",i,i+n/2);
    16         }
    17     }
    18     return 0;
    19 }
    View Code
  • 相关阅读:
    投票练习
    多条件查询
    PHP 购物车
    PHP TP模型
    PHP smarty函数
    PHP smarty复习
    PHP smarty缓存
    PHP phpcms
    php smarty查询分页
    PHP Smarty变量调节器
  • 原文地址:https://www.cnblogs.com/xkui/p/4556568.html
Copyright © 2011-2022 走看看