zoukankan      html  css  js  c++  java
  • cf550D. Regular Bridge(构造)

    题意

    给出一个$k$,构造一个无向图,使得每个点的度数为$k$,且存在一个桥

    Sol

    神仙题

    一篇写的非常好的博客:http://www.cnblogs.com/mangoyang/p/9302269.html

    我简单的来说一下构造过程

    首先$n$是偶数的时候无解

    奇数的时候:我们拿出两个点作为桥

    先构建一条桥边,对于两个端点分别做同样操作:

    新建$k1$个点,每个点向端点连边

    再新建$k−1$个点,每个点向相邻的点连边

    对于两层点形成的二分图,两两之间连边

    /*
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<vector>
    #include<set>
    #include<queue>
    #include<cmath>
    //#include<ext/pb_ds/assoc_container.hpp>
    //#include<ext/pb_ds/hash_policy.hpp>
    #define Pair pair<int, int>
    #define MP(x, y) make_pair(x, y)
    #define fi first
    #define se second
    //#define int long long 
    #define LL long long 
    #define ull unsigned long long 
    #define rg register 
    #define pt(x) printf("%d ", x);
    //#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 22)], *p1 = buf, *p2 = buf;
    //char obuf[1<<24], *O = obuf;
    //void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
    //#define OS  *O++ = ' ';
    using namespace std;
    //using namespace __gnu_pbds;
    const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
    const double eps = 1e-9;
    inline int read() {
        char c = getchar(); int x = 0, f = 1;
        while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
    int K, N, M;
    void Build(int t) {
        for(int i = t + 1; i <= t + K - 1; i++)
            printf("%d %d
    ", t, i);
        for(int i = t + 1; i <= t + K - 1; i++)
            for(int j = t + K ; j <= 2 * K + t - 2; j++)
                printf("%d %d
    ", i, j);
        for(int i = K + t; i <= 2 * K + t - 2; i++)
            if(((t & 1) && (!(i & 1))) || ((!(t & 1)) && (i & 1))) printf("%d %d
    ", i, i + 1);
    }
    main() {
        K = read();
        if(!(K & 1)) {puts("NO"); return 0;}
        puts("YES");
        N = (2 * (K - 1) + 1) * 2, M = N * K / 2;
        printf("%d %d
    ", N, M);
        printf("%d %d
    ", 1, N / 2 + 1);
        Build(1); 
        Build(N / 2 + 1);
        return 0;
    }
    /*
    2 2 1
    1 1
    2 1 1
    */
  • 相关阅读:
    SVN添加自动忽略文件.settings .project .classpath target等
    Ueditor富文本编辑器
    服务器搭建及使用
    Java各种对象(PO,BO,VO,DTO,POJO,DAO,Entity,JavaBean,JavaBeans)的区分
    Oracle 查询交集、并集、差集
    Oracle sql优化工具
    移动端click时间延迟300
    腾讯地图位置展示组件用法
    百度地图 卫星 二维
    $.load()的用法
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9571267.html
Copyright © 2011-2022 走看看