UVa 10720 - Graph Construction
题目大意:给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的更多相关文章
- UVa 10720 - Graph Construction(Havel-Hakimi定理)
题目链接: 传送门 Graph Construction Time Limit: 3000MS Memory Limit: 65536K Description Graph is a coll ...
- UVA 10720 Graph Construction 贪心+优先队列
题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vert ...
- UVA10720 Graph Construction 度序列可图性
Luogu传送门(UVA常年上不去) 题意:求一个度序列是否可变换为一个简单图.$\text{序列长度} \leq 10000$ 题目看起来很简单,但是还是有一些小细节需要注意首先一个简单的结论:一张 ...
- uva 193 Graph Coloring(图染色 dfs回溯)
Description You are to write a program that tries to find an optimal coloring for a given graph. Col ...
- UVa 1515 - Pool construction(最小割)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 1515 Pool construction 最大流跑最小割
Pool construction You are working for the International Company for Pool Construction, a constructio ...
- UVA 1515 Pool construction 水塘(最大流,经典)
题意: 给一个h*w的矩阵,每个格子中是'#'和'.'两个符号之一,分别代表草和洞.现在要将洞给围起来(将草和洞分离),每条边需花费b元(即将一个洞包起来需要4边,将2个连续的洞包起来需要6边,省了2 ...
- UVA 193 Graph Coloring 图染色 DFS 数据
题意:图上的点染色,给出的边的两个点不能都染成黑色,问最多可以染多少黑色. 很水的一题,用dfs回溯即可.先判断和当前点相连的点是否染成黑色,看这一点是否能染黑色,能染色就分染成黑色和白色两种情况递归 ...
- UVa 459 - Graph Connectivity
题目大意:给你一个无向图的顶点和边集,让你求图中连通分量的个数.使用并查集解决. #include <cstdio> #include <cstring> #define MA ...
随机推荐
- MediaScanner与音乐信息扫描==
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=98713 =================================== ...
- gen_grant_sel.sql
set echo off feedback off verify off pagesize 0 linesize 120 define v_grantee=&1 define v_grant_ ...
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
web.xml中的加载顺序为:listener > filter > servlet > spring. 其中filter的执行顺序是filter-mapping在web.xml中出 ...
- codeforces 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...
- rsa or dsa?
http://www.linuxquestions.org/questions/linux-security-4/which-is-better-rsa-or-dsa-public-key-12593 ...
- HTTP协议详解 转自小坦克
-- 此文章是转载小坦克的;直接复制文章的目的是因为原文章地址经常被重置,找不到原来的文章.小坦克博客园主页:https://home.cnblogs.com/u/TankXiao/ 当今web程序的 ...
- 控制textbook输入字符
在KeyPress事件中假如如下代码此实例表示可输入数字退格和“.”. 具体字符KeyChar见连接 http://www.cnblogs.com/linji/archive/2012/10/24/2 ...
- WEB网页输入框的默认键盘类型控制
参考资料 http://www.w3school.com.cn/html5/att_input_type.asp : 语法 <input type="value"> 属 ...
- SQL Server 2012 - Transact-SQL
变量 --全局变量 select @@VERSION --局部变量 declare @i int set @i=5 select @i 通配符: like 'joh%', %任意长度的任意字 ...
- 通过ionice和nice降低shell脚本运行的优先级
对于一些运行时会造成系统满载的脚本, 例如数据库备份, 会影响当时其他服务的响应速度, 可以通过ionice和nice对其IO优先级和CPU优先级进行调整例如降低"/usr/local/bi ...