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 qingshuang100 at 2005-02-23 21:21:06 on Problem 1659
In Reply To:刚才的程序沾错了 Posted by:liuminghai at 2005-02-23 15:11:42
> #include <iostream.h>
> #include <memory.h>
> 
> int n, t, x[20], map[20][20];
> void main()
> {
> 	int i, j, k, max, min, t1, t2, boolean;
> 	cin>>t;
> 	for (i = 0; i < t; i++) {
> 		memset(x, 0, sizeof(x));
> 		memset(map, 0, sizeof(map));
> 		boolean = 0;
> 		cin>>n;
> 		for (j = 0; j < n; j++) {
> 			cin>>x[j]; 
> 			if (x[j]) boolean = 1;
> 		}
> 		while (boolean) {
> 			min = 100; max = 0;
> 			for (j = 0; j < n; j++) 
> 				if (x[j] < min && x[j]) {
> 					min = x[j]; t1 = j;
> 				}
> 			for (j = n - 1; j >= 0; j--)
> 				if (x[j] > max) {
> 					max = x[j]; t2 = j;
> 				}
> 			if (min == 100) break;
> 			if (t1 == t2) {
> 				boolean = 0; break;
> 			}
> 			if (t1 == t2) 
> 				for (j = t1 + 1; j < n; j++)
> 					if (max == x[j]) {
> 						t2 = j; break;
> 					}
> 			if (map[t1][t2] == 1) {
> 				boolean = 0; break;
> 			}
> 			x[t1]--; x[t2]--;
> 			map[t1][t2] = 1; map[t2][t1] =1;
> 		}
> 		if (boolean == 0) {
> 			cout<<"NO"<<endl;
> 			if (i < t - 1) cout<<endl;
> 		}
> 		else {
> 			cout<<"YES"<<endl;
> 			for (j = 0; j < n; j++) {
> 				for (k = 0; k < n - 1; k++)
> 					cout<<map[j][k]<<' ';
> 				cout<<map[j][k]<<endl;
> 			}
> 			if (i < t - 1) 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