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 |
真的不知道哪错了,找了半天了,求解#include <stdio.h> #include <stdlib.h> #include <string.h> #define maxn 2010 struct edge{ int a,b,value; }bian[maxn]; char ch[maxn][10]; int n,p[maxn]; int isbig(const void* a,const void* b) { edge ta=*(edge *)a; edge tb=*(edge *)b; if (ta.value<tb.value) return -1; if (ta.value>tb.value) return 1; return 0; } int find(int a) { return (p[a]==0)?a:( p[a]=find(p[a]) ); } int compare(int a,int b) { int i,t1=0; for (i=0;i<7;i++) if (ch[a][i]!=ch[b][i]) t1++; return t1; } int main(void) { freopen("1789.in","r",stdin); freopen("1789.out","w",stdout); int i,j,t,v1,v2,temp=0,count=0; while(1){ temp=0; count=0; scanf("%d\n",&n); if (n==0) return 0; for (i=1;i<=n;i++) scanf("%s\n",&ch[i]); for (i=1;i<=n;i++) for (j=1;j<=n;j++){ t=compare(i,j); if (t){ bian[++temp].a=i; bian[temp].b=j; bian[temp].value=t; } } qsort(&bian[1],temp,sizeof(edge),isbig); memset(p,0,sizeof(p)); for (i=1;i<=temp;i++){ v1=find(bian[i].a); v2=find(bian[i].b); if (v1!=v2){ p[v2]=v1; count+=bian[i].value; } } printf("The highest possible quality is 1/%d.\n",count); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator