zoukankan      html  css  js  c++  java
  • Frogs' Neighborhood

    http://poj.org/problem?id=1659

    题意: 输入每个点的度 要用邻接矩阵输出可能的图

    havel 定理

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    struct node{int x;int w;}no[10000];
    int p[1002][1002],n;
    int cmp(node a,node b)
    {
        return a.w>b.w;
    }
    
    int solve()
    {
        int j,i,k;
        for(i=0;i<n;i++)
        {
            sort(no+i,no+n,cmp);
            if(no[i].w>n-i-1)
                return -1;
            for(j=i+1;j<no[i].w+i+1&&j<n;j++)
            {
                no[j].w--;
                if(no[j].w<0)
                    return -1;
                p[no[i].x][no[j].x ]=p[no[j].x][no[i].x]=1;
            }
        }
        return 0;
    }
    
    int main()
    {
        int i,j,m,t,flag=0;
        scanf("%d",&t);
        for(int k=0;k<t;k++)
        {
    
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%d",&no[i].w);
                no[i].x=i;
            }
            memset(p,0,sizeof(p));
            if(flag==0)
                flag=1;
            else printf("
    ");
            if(solve()==-1)
                printf("NO
    ");
            else 
            {
                printf("YES
    ");        
                for(i=0;i<n;i++)
                {
                    for(j=0;j<n;j++)
                        printf("%d ",p[i][j]);
                    printf("
    ");
                }
            }
            
        }
        return 0;
    }
  • 相关阅读:
    docker
    opencart
    Why is setTimeout(fn, 0) sometimes useful?
    linux下php环境配置
    xampp for linux
    Where to go from here
    freefcw/hustoj Install Guide
    khan academy js
    SDWebImage
    基于OpenCV 的iOS开发
  • 原文地址:https://www.cnblogs.com/assult/p/3237925.html
Copyright © 2011-2022 走看看