| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
刚才的程序沾错了In Reply To:晕,算法是构造,但是编了很久就是不对,是不是有什么特殊数据没有考虑到呢?? 求助 Posted by:liuminghai at 2005-02-23 14:57:30 #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator