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 1012662902 at 2014-10-04 21:55:55 on Problem 1659
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
using namespace std;

struct node{
	int e, num;
}a[15];

bool cmp(node a,node b){
	return a.num>b.num;
}

main()
{
	int n;
	int i, j, k, t;
	int b[15][15];
	cin>>t;
	while(t--){
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&a[i].num);
			a[i].e=i;
		}
		int ci=0;
		memset(b,0,sizeof(b));
		while(ci<n-1){
			ci++;
			sort(a,a+n,cmp);
			for(i=1;i<=a[0].num;i++) a[i].num--,b[a[0].e][a[i].e]=b[a[i].e][a[0].e]=1;
			a[0].num=0;
		}
		int f=1;
		for(i=0;i<n;i++){
			if(a[i].num<0){
				f=0;break;
			}
		}
		if(!f) printf("NO\n\n");
		else {
			printf("YES\n");
			for(i=0;i<n;i++){
				printf("%d",b[i][0]);
				for(j=1;j<n;j++){
					printf(" %d",b[i][j]);
				}
				cout<<endl;
			}
			cout<<endl;
		}
	}
}

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