标签:border str 个数 技术 blank return bcd color none
这道题在如何判断能否存图上想了好久,最后还是参考了网上的题解就了解到了这样一个定理——Havel-Hakimi定理
下面给出例子(例子转自https://blog.51cto.com/sbp810050504/883904)
下标
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
值
|
4
|
7
|
7
|
3
|
3
|
3
|
2
|
1
|
下标
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
值
|
7
|
7
|
4
|
3
|
3
|
3
|
2
|
1
|
下标
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
值
|
7
|
4
|
3
|
3
|
3
|
2
|
1
|
下标
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
值
|
6
|
3
|
2
|
2
|
2
|
1
|
0
|
下标
|
1
|
2
|
3
|
4
|
5
|
6
|
值
|
2
|
1
|
1
|
1
|
0
|
-1
|
5
|
4
|
3
|
3
|
2
|
2
|
2
|
1
|
1
|
1.
|
4
|
3
|
3
|
2
|
2
|
2
|
1
|
1
|
1.
|
3
|
2
|
2
|
1
|
1
|
2
|
1
|
1
|
1.
|
3
|
2
|
2
|
2
|
1
|
1
|
1
|
1
|
1.
|
2
|
2
|
2
|
1
|
1
|
1
|
1
|
1.
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1.
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1.
|
1
|
1
|
1
|
1
|
1
|
1
|
1.
|
0
|
1
|
1
|
1
|
1
|
1
|
1.
|
1
|
1
|
1
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
1
|
1
|
0
|
0
|
1
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
1
|
0
|
0
|
0
|
0
|
0
|
0
|
#include <iostream> #include <algorithm> #include <cstring> using namespace std; #define maxn 1000 + 5 struct node{ int pos; int degree; }a[maxn]; int ans[maxn][maxn]; bool cmp (node a,node b){ return a.degree > b.degree; } int main() { int n, x = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].degree; a[i].pos = i; if (!a[i].degree) x++; } //由Havel–Hakimi可知不能成图的条件为: //当所有点的度不为都0且存在点的度为0 //这样的话降序减下去,就必然出现度为负的点 if (x != 0 && x != n) { cout << "None\n"; return 0; } for (int i = 0; i < n; i++) { sort(a+i, a+n, cmp); if (a[i].degree==0) break; if(a[i].degree > n-1-i) { cout << "None"; return 0; } for (int j = 1 + i; j <= a[i].degree + i; j++) { a[j].degree--; if (a[j].degree < 0) { cout << "None"; return 0; } ans[a[i].pos][a[j].pos] = ans[a[j].pos][a[i].pos] = 1; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j == 0) cout << ans[i][j]; else cout << " " << ans[i][j]; } cout << endl; } return 0; }
标签:border str 个数 技术 blank return bcd color none
原文地址:https://www.cnblogs.com/Vikyanite/p/11838352.html