uva 10720 Graph Construction
2015-01-23 20:58
274 查看
题意:给你一串度序列,问该序列是不是可图的。
思路:Havel-Hakimi定理。每次去掉一个度数最大的节点a[i],对其后的a[i]项减一,若度数出现负数或超出范围则是不可图的。
思路:Havel-Hakimi定理。每次去掉一个度数最大的节点a[i],对其后的a[i]项减一,若度数出现负数或超出范围则是不可图的。
#include <iostream> #include <algorithm> using namespace std; int n; int a[10005]; bool cmp(const int a, const int b){ return a > b; } bool input(){ cin>>n; if(n == 0) return false; for(int i= 0; i < n; i++) cin>>a[i]; return true; } bool check(){ for(int i = 0; i < n; i++){ sort(a+i,a+n,cmp); int d = a[i]; if(i+d >= n) return false; for(int j = i+1; j <= i+d; j++){ a[j]--; if(a[j] < 0) return false; } } return true; } int main(){ while(input()){ if(check()) cout<<"Possible\n"; else cout<<"Not possible\n"; } return 0; }
相关文章推荐
- UVa 10720 - Graph Construction(Havel-Hakimi定理)
- [贪心]UVA10720 - Graph Construction
- uva 10720 Graph Construction()
- UVa10720 - Graph Construction
- UVA 10720 Graph Construction
- UVA 10720 Graph Construction
- UVA 10720 Graph Construction 贪心+优先队列
- uva 10720
- uva10720 - Graph Construction(图重建)
- UVA10720- Graph Construction
- UVa:10720 Graph Construction
- Havel-Hakimi定理(判断一个序列是否可图) UVA 10720
- uva10720(Graph Construction)贪心+havel定理
- UVa 10720 - Graph Construction
- uva10720 - Graph Construction(简单图的判定)
- uva 10720(贪心)
- uva10720
- UVA 10720
- UVa10720
- uva10720 Graph Construction