hdu 2454 Degree Sequence of Graph G (推断简单图)

///已知各点的度,推断是否为一个简单图
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[1010];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int t,n,i,j;
    scanf("%d",&t);
    while(t--)
    {
        int flag=1;
        scanf("%d",&n);
        for (i=0; i<n; i++)
            scanf("%d",&a[i]);
        sort(a,a+n,cmp);
        while (a[0] && a[n-1]>=0)
        {
            int i = 1;
            while (a[0]--)
            {
                --a[i++];
            }
            ++a[0];
            sort(a,a+n,cmp);
        }
        if(a[n-1]<0)
            printf("no\n");
        else
            printf("yes\n");
    }
    return 0;
}

1。Havel-Hakimi定理主要用来判定一个给定的序列是否是可图的。

2。首先介绍一下度序列:若把图 G 全部顶点的度数排成一个序列 S。则称 S 为图 G 的度序列。

3,一个非负整数组成的有限序列假设是某个无向图的序列,则称该序列是可图的。

4,判定过程:(1)对当前数列排序,使其呈递减,(2)从S【2】開始对其后S【1】个数字-1,(3)一直循环直到当前序列出现负数(即不是可图的情况)或者当前序列全为0 (可图)时退出。

5,举例:序列S:7,7,4,3,3,3,2,1  删除序列S的首项 7 。对其后的7项每项减1,得到:6,3,2,2,2,1,0,继续删除序列的首项6,对其后的6项每项减1。得到:2,1,1,1,0,-1。在这一点上已经出现了负。因此,序列图不可。

版权声明:本文博客原创文章,博客,未经同意,不得转载。

时间: 2024-11-05 22:39:21

hdu 2454 Degree Sequence of Graph G (推断简单图)的相关文章

hdu 2454 Degree Sequence of Graph G (判断简单图)

///已知各点的度,判断是否为一个简单图 #include<stdio.h> #include<algorithm> #include<string.h> using namespace std; int a[1010]; bool cmp(int x,int y) { return x>y; } int main() { int t,n,i,j; scanf("%d",&t); while(t--) { int flag=1; sca

HDU 2454 Degree Sequence of Graph G (可简单图化的判定 havel定理)

题目链接:HDU 2454 Degree Sequence of Graph G 题意:给出N个点的度(简单图),问能能否画出个图,(其实就是给出一个串非负的序列是否有对应的图存在) 没见过这个定理 题意真的难懂. havel定理就是一个给出一串非负的序列,存在一个无向图使得图中各点的度与此序列一一对应,则称此序列可图化.简单图的话就是,可简单图化. 可简单图化的判定(Havel定理):把序列排成不增序,即d1>=d2>=-->=dn,则d可简单图化当且仅当d'={d2-1,d3-1,-

HDU 2454 Degree Sequence of Graph G(Havel定理 判断简单图的存在)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2454 Problem Description Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep love and yearns for the boundless oceans.

HDOJ题目2454 Degree Sequence of Graph G(判断是否是简单图)

Degree Sequence of Graph G Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1811    Accepted Submission(s): 750 Problem Description Wang Haiyang is a strong and optimistic Chinese youngster. Alt

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

HDU 1560 DNA sequence(DNA序列)

p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo

HDU - 1711 Number Sequence KMP字符串匹配

HDU - 1711 Number Sequence Time Limit: 5000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <=

hdu 4441 Queue Sequence(splay)

题目链接:hdu 4441 Queue Sequence 这题看了题解写的,题解传送门 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 #define ls l,m,rt<<1 4 #define rs m+1,r,rt<<1|1 5 using namespace std; 6 typedef long long ll; 7 8 const int N=1e6+7; 9 i

hdu 5297 Y sequence(容斥)

题目链接:hdu 5297 Y sequence 考虑62以内的指数,x为奇数个质数因子,就减掉,偶数个加上.计算x为指数的不满足数直接pow(n,1/x)即可. #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <algorithm> using namespace std; type