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 |
搞定了。1258 Accepted 268K 16MSIn Reply To:Re:求教高人 Posted by:orangelegend at 2008-08-20 14:53:35 #include <stdio.h> #include <algorithm> using namespace std; struct line { int s,e,len; }l[20000]; int flag[128]; bool cmp(struct line &a,struct line &b) { return a.len < b.len; } int main() { int i,j,k,n,len,count; int totallen; while (scanf("%d",&n) != EOF) { k = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%d",&len); if (i < j) { l[k].s = i; l[k].e = j; l[k].len = len; k++; } } } sort(&l[0],&l[k],cmp); memset(flag,0,sizeof(flag)); flag[l[0].s] = 1; totallen = 0; count = 0; for (i = 0; i < k; i++) { if (flag[l[i].s] == 1 && flag[l[i].e] == 0) { totallen += l[i].len; flag[l[i].e] = 1; count++; 改了这里 i = 0; } else if (flag[l[i].s] == 0 && flag[l[i].e] == 1) { totallen += l[i].len; flag[l[i].s] = 1; count++; 改了这里 i = 0; } if (count == n - 1) break; } printf("%d\n",totallen); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator