| ||||||||||
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 |
有什么特殊数据吗?老是WA#include<stdio.h> #include<string.h> const int maxint=2000; const int max=100000000; int dis[maxint][maxint]; int lowcost[maxint],sum; char s[maxint][8]; bool used[maxint]; int distance(char *a,char *b) { int i,sum=0; for(i=0;a[i]!='\0';i++) sum+=(a[i]!=b[i]); return sum; } int main() { int i,j,k,u,n,min; while(scanf("%d",&n)!=EOF&&n) { for(i=0;i<n;i++) { scanf("%s",s[i]); for(j=i-1;j>=0;j--) dis[i][j]=dis[j][i]=distance(s[i],s[j]); } used[0]=1; for(i=1;i<n;i++) { lowcost[i]=dis[0][i]; used[i]=0; } sum=0; for(i=1;i<n;i++) { min=max; for(j=1;j<n;j++) { if(used[j]==0&&lowcost[j]<min) { u=j; min=lowcost[j]; } } used[u]=1; sum+=min; for(j=1;j<n;j++) { if(used[j]==0) { if(lowcost[u]+dis[u][j]<lowcost[j]) lowcost[j]=lowcost[u]+dis[u][j]; } } } printf("The highest possible quality is 1/%d.\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator