hdu 2454 Degree Sequence of Graph G
2011-08-25 10:50
513 查看
给你点的度的序列,问你是否能构成一个简单图。
我开始想的很简单,当然很随意的就WA掉了。
后来觉得应该有判定方法,百度搜了下还真有 = =。。见这里http://wenku.baidu.com/view/4108997101f69e3143329415.html
后来看网上还有一种方法就是拓排了,把对应大的度数的点在其余每个点都减,类似拓排。
我好笨 = =。。。怎么没多想想呢。
我开始想的很简单,当然很随意的就WA掉了。
后来觉得应该有判定方法,百度搜了下还真有 = =。。见这里http://wenku.baidu.com/view/4108997101f69e3143329415.html
后来看网上还有一种方法就是拓排了,把对应大的度数的点在其余每个点都减,类似拓排。
我好笨 = =。。。怎么没多想想呢。
#include <map> #include <set> #include <queue> #include <stack> #include <math.h> #include <time.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <string> #include <algorithm> #define MID(x,y) ( ( x + y ) >> 1 ) #define L(x) ( x << 1 ) #define R(x) ( x << 1 | 1 ) #define BUG puts("here!!!") #define STOP system("pause") using namespace std; const int MAX = 1010; int deg[MAX]; bool check(int n) { for(int i=1; i<=n; i++) { int s = 0; for(int k=1; k<=i; k++) s += deg[k]; int s2 = 0; for(int k=i+1; k<=n; k++) s2 += min(i, deg[k]); if( s > i*(i-1) + s2 ) return false; } return true; } int main() { int ncases, n; scanf("%d", &ncases); while( ncases-- ) { scanf("%d", &n); int sum = 0; for(int i=1; i<=n; i++) { scanf("%d", °[i]); sum += deg[i]; } sort(deg+1, deg+n+1, greater<int>()); if( sum % 2 == 1 ) { printf("no\n"); continue; } if( check(n) ) printf("yes\n"); else printf("no\n"); } return 0; }
相关文章推荐
- HDU 2454 Degree Sequence of Graph G(Havel-Hakimi定理,图论基础)
- hdu 2454 Degree Sequence of Graph G (推断简单图)
- hdu 2454 Degree Sequence of Graph G
- hdu 2454 Degree Sequence of Graph G (判断简单图)
- hdu 2454 Degree Sequence of Graph G
- HDU 2454 Degree Sequence of Graph G(Havel定理 推断一个简单图的存在)
- HDU 2454 Degree Sequence of Graph G(Havel定理 判断简单图的存在)
- hdu2454 Degree Sequence of Graph G(havel定理)
- HDU 2454 Degree Sequence of Graph G(Heavel定理)
- Degree Sequence of Graph G(Hdu_oj 2454)
- HDU 2454 Degree Sequence of Graph G (可简单图化的判定 havel定理)
- HDOJ题目2454 Degree Sequence of Graph G(判断是否是简单图)
- [HDOJ2454]Degree Sequence of Graph G
- hdu2454 Degree Sequence of Graph G (Havel-Hakimi定理,可图化判定)
- HDU 2817 A sequence of numbers(数列,简单题)
- HDU - 3415 Max Sum of Max-K-sub-sequence(单调队列)
- HDU 3415 Max Sum of Max-K-sub-sequence 单调队列题解
- HDU 3415 Max Sum of Max-K-sub-sequence
- hdu Max Sum of Max-K-sub-sequence 单调队列优化DP
- 单调队列——HDU 3415 Max Sum of Max-K-sub-sequence