您的位置:首页 > 其它

uva 10720 Graph Construction

2013-09-02 18:25 232 查看
题意:求是否可以构成图,用到了这个Havel定理
点击打开链接

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 10002;

int cmp(const void *a,const void *b)
{
    return *(int *)b - *(int *)a;
}
int a[MAXN];

int solve(int n)
{
    for (int i = 0; i < n; i++)
    {
        qsort(&a[i],n - i,sizeof(a[0]),cmp);
        if (a[i] >= n)
            return 0;
        if (a[i] == 0)
            return 1;
        for (int j = i + 1; j <= a[i] + i; j++)
        {
            --a[j];
            if (a[j] < 0)
                return 0;
        }
    }
    return 1;
}

int main()
{
    int n;
    while (scanf("%d",&n) != EOF && n)
    {
        for (int i = 0; i < n; i++)
            scanf("%d",&a[i]);
        
        if (solve(n))
            printf("Possible\n");
        else printf("Not possible\n");
    }
    return 0;
}






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: