Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

离散和很多年前数学竞赛学过的可图化判定竟然在这里看到了,不贴代码天理不容啊~

Posted by 1000010314 at 2012-04-13 18:54:07 on Problem 1659
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

bool map[12][12];
struct node
{
    short d;
    short id;
};

inline bool cmp(node a,node b)
{
    return b.d<a.d;
}

int main()
{
    short T,N,k;bool p=true;
    for(scanf("%hd",&T);T>0;T--)
    {
        scanf("%hd",&N);memset(map,false,sizeof(map));k=N;
        node * data=new node [N+1];
        for(short i=0;i<N;i++){scanf("%hd",&data[i].d);data[i].id=i;}
        while(N>0)
        {
            sort(data,data+N,cmp);
            if(data[0].d>=N||data[0].d<0)
            {
                p=false;
                break;
            }
            for(int i=1;i<=data[0].d;i++)
            {
                map[data[0].id][data[i].id]=true;
                map[data[i].id][data[0].id]=true;
                data[i].d--;
            }
            data=&data[1];
            N--;
        }
        if(!p)
        {
            printf("NO\n");
            p=true;
        }
        else
        {
            printf("YES\n");
            for(int i=0;i<k;i++)
            {
                for(int j=0;j<k;j++)
                {
                    cout<<map[i][j]<<" ";
                }
                printf("\n");
            }
        }
        printf("\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator