标签:++ led origin vegetable define where mission sam style
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 27703 | Accepted: 10769 |
Description
Input
Output
Sample Input
4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0
Sample Output
The highest possible quality is 1/3.
Source
#include<cstdlib> #include<stdio.h> #include<cstring> #include<iostream> #include<algorithm> #define N 2001 using namespace std; struct Edge { int x,y,z; }edge[N*N]; int n,m,fa[N],ans,sum,tot; char a[N][8]; int cmp(Edge a,Edge b) { return a.z<b.z; } int found(int x) { return fa[x]==x?x:fa[x]=found(fa[x]); } int main() { while(scanf("%d",&n),n) { memset(a,0,sizeof(a)); ans=0; for(int i=1;i<=n;i++) cin>>a[i]; tot=0; for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++) { sum=0; for(int k=0;k<7;k++) if(a[i][k]!=a[j][k]) sum++; edge[++tot].x=i; edge[tot].y=j; edge[tot].z=sum; } sort(edge+1,edge+1+tot,cmp); for(int i=1;i<=n;i++) fa[i]=i; sum=0; for(int i=1;i<=tot;i++) { int x=edge[i].x,y=edge[i].y; int fx=found(x),fy=found(y); if(fx!=fy) { fa[fy]=fx; sum++; ans+=edge[i].z; } if(sum==n-1) break; } printf("The highest possible quality is 1/%d.\n",ans); } return 0; }
标签:++ led origin vegetable define where mission sam style
原文地址:http://www.cnblogs.com/z360/p/6869751.html