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 Bang1314 at 2018-04-02 20:05:50 on Problem 1659
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define ll long long
#define lowbit(i) i&(-i)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

const int maxn=15;
const int mod=1e9+7;
const double eps=1e-6;

bool graph[maxn][maxn];

struct node{
    int degree;
    int mark;
    bool operator<(const node &a){
        return degree>a.degree;
    }
};

typedef struct node Map;

Map mp[maxn];

int N;

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        memset(graph,false,sizeof(graph));
        scanf("%d",&N);
        for(int i=1;i<=N;i++){
            scanf("%d",&mp[i].degree);
            mp[i].mark=i;
        }
        int K;
        bool flag=false;
        for(K=1;K<=N;K++){
                if(mp[K].degree>N-K||mp[K].degree<0) break;
                sort(mp+K,mp+N+1);
                for(int j=K+1;j<=K+mp[K].degree;j++){
                    if(mp[j].degree<=0) {
                        flag=true;
                            break;
                    }
                    mp[j].degree--;
                    graph[mp[K].mark][mp[j].mark]=graph[mp[j].mark][mp[K].mark]=true;
                }
            if(flag) break;
        }
        if(K<=N) printf("NO\n");
        else {
            printf("YES\n");
            for(int i=1;i<=N;i++){
                int j;
                for(j=1;j<N;j++)
                    printf("%d ",graph[i][j]?1:0);
                printf("%d\n",graph[i][j]?1:0);
            }
        }
        if(T) 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