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 ...
随机推荐
- linux下GBK->UTF-8文件编码批量转换脚本
find default -type d -exec mkdir -p utf/{} \;find default -type f -exec iconv -f GBK -t UTF-8 {} -o ...
- zf-关于荆州图片链接和弹出页面问题
target="_blank" 属性不能写在div 里 所以我在里面加了个a标签 这个属性的作用就是弹出一个新的页面,不会在原先的页面上换地址 如果 style 的加载图片卸载cs ...
- Html 中表单提交的一些知识总结——防止表单自动提交,以及submit和button提交表单的区别
转自:http://jackaudrey.blog.163.com/blog/static/1314217882010590041833/ 在页面中有多个input type="text&q ...
- 【gcd】 最大公约数
int gcd(int a,int b) { int r; ) { r=a%b; a=b; b=r; } return a; }
- Gulp自动构建前端开发一体化
gulp是基于Nodejs的自动任务运行器, 她能自动化地完成 javascript/coffee/sass/less/html/image/css 等文件的的测试.检查.合并.压缩.格式化.浏览器自 ...
- memory runs at single channel问题解决
memory runs at single channel 解决方案:开机后按DEL ,然后进入BIOS 选择第一项,回车! advanced下面的有个momori什么什么的,选择disable. m ...
- Memcached缓存系统介绍及安装
1.什么是Memcached 1.1.Memcached概述 Memcached是一个免费的开源的.高性能的.具有又分布式内存对象的缓存系统,它通过减轻数据库负载加速动态WEB应用, 1.2.Memc ...
- ARC下需要注意的内存管理
ARC下需要注意的内存管理 2016/04/03 · iOS开发 · 内存管理 分享到:1 原文出处: 一不(@luoyibu) 之前发了一篇关于图片加载优化的文章,还是引起很多人关注的,不过也 ...
- [iOS]C语言技术视频-11-指针变量练习一(交换值)
下载地址: 链接: http://pan.baidu.com/s/1pJIcGm3 密码: s83p
- hibernate---关联关系的 crud_cascade_fetch
CRUD怎么写?? 存user信息, 自动存group信息 user.java package com.bjsxt.hibernate; import javax.persistence.Cascad ...