题目大意:给n个整数, 分别代表图中n个顶点的度,判断是否能构成一张图。

  看到这个题后,除了所有数之和应该为偶数之外,没有别的想法了,只好在网上搜解题报告了。然后了解了Havel-Hakimi定理。之后的事情就简单了。

 #include <cstdio>
#include <algorithm>
#include <functional>
using namespace std; #define MAXN 10000+10 int a[MAXN];
int n; bool Havel_Hakimi()
{
for (int i = ; i < n-; i++)
{
sort(a+i, a+n, greater<int>());
if (i + a[i] >= n) return false;
for (int j = i+; j <= i+a[i]; j++)
{
a[j]--;
if (a[j] < ) return false;
}
}
if (a[n-]) return false;
return true;
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
while (scanf("%d", &n) && n)
{
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
if (Havel_Hakimi()) printf("Possible\n");
else printf("Not possible\n");
}
return ;
}

UVa 10720 - Graph Construction的更多相关文章

  1. UVa 10720 - Graph Construction(Havel-Hakimi定理)

    题目链接: 传送门 Graph Construction Time Limit: 3000MS     Memory Limit: 65536K Description Graph is a coll ...

  2. UVA 10720 Graph Construction 贪心+优先队列

    题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vert ...

  3. UVA10720 Graph Construction 度序列可图性

    Luogu传送门(UVA常年上不去) 题意:求一个度序列是否可变换为一个简单图.$\text{序列长度} \leq 10000$ 题目看起来很简单,但是还是有一些小细节需要注意首先一个简单的结论:一张 ...

  4. uva 193 Graph Coloring(图染色 dfs回溯)

    Description You are to write a program that tries to find an optimal coloring for a given graph. Col ...

  5. UVa 1515 - Pool construction(最小割)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. UVA 1515 Pool construction 最大流跑最小割

    Pool construction You are working for the International Company for Pool Construction, a constructio ...

  7. UVA 1515 Pool construction 水塘(最大流,经典)

    题意: 给一个h*w的矩阵,每个格子中是'#'和'.'两个符号之一,分别代表草和洞.现在要将洞给围起来(将草和洞分离),每条边需花费b元(即将一个洞包起来需要4边,将2个连续的洞包起来需要6边,省了2 ...

  8. UVA 193 Graph Coloring 图染色 DFS 数据

    题意:图上的点染色,给出的边的两个点不能都染成黑色,问最多可以染多少黑色. 很水的一题,用dfs回溯即可.先判断和当前点相连的点是否染成黑色,看这一点是否能染黑色,能染色就分染成黑色和白色两种情况递归 ...

  9. UVa 459 - Graph Connectivity

    题目大意:给你一个无向图的顶点和边集,让你求图中连通分量的个数.使用并查集解决. #include <cstdio> #include <cstring> #define MA ...

随机推荐

  1. hdu_4352_XHXJ's LIS(数位DP+状态压缩)

    题目连接:hdu_4352_XHXJ's LIS 题意:这题花大篇篇幅来介绍电子科大的一个传奇学姐,最后几句话才是题意,这题意思就是给你一个LL范围内的区间,问你在这个区间内最长递增子序列长度恰为K的 ...

  2. centos dmesg

    linux dmesg命令详解   功能说明:显示开机信息. 语 法:dmesg [-cn][-s ] 补充说明:kernel会将开机信息存储在ring buffer,若是开机时来不及查看信息,可利用 ...

  3. xshell 图形化连接ubuntu

    原文: http://jingyan.baidu.com/article/d45ad148967fcd69552b80f6.html Xmanager4系列软件是一套非常好的liunx远程操作,尤其是 ...

  4. offsetXXX和scollXXX的一些操作

    <!doctype html><html><head><meta charset="utf-8"><title>offs ...

  5. They Are Everywhere

    They Are Everywhere Sergei B., the young coach of Pokemons, has found the big house which consists o ...

  6. 一个完整的ant build.xml

    <?xml version="1.0" encoding="UTF-8"?> <project name="genwar" ...

  7. PAT (Advanced Level) 1077. Kuchiguse (20)

    最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...

  8. Selenium IDE安装

    1. 网上下载firefox30版本 http://www.9ht.com/xz/78637.html#addressWrap Selenium IDE 2.9.0下载   http://www.pc ...

  9. STM8不用手动复位进入自带Bootloader方法(串口下载)

    源:STM8不用手动复位进入自带Bootloader方法(串口下载) STM8不用手动复位进入自带Bootloader方法(串口下载)除非STM8片子的空的,如果复位运行的是自带Bootloader, ...

  10. Subsequences Summing to Sevens

    Subsequences Summing to Sevens 题目描述 Farmer John's N cows are standing in a row, as they have a tende ...