http://poj.org/problem?id=1789
Test instructions: To put it simply, a string of n rows is given, and the distance between the string and the string is compared with a few different letters, and then the number of the shortest distance between the N-row string is directly or indirectly connected. (Spanning Tree template)
The topic of writing the minimum spanning tree really feels much better than the other topics. (%>_<%)
#include <stdio.h>#include<string.h>#include<math.h>#include<queue>#include<algorithm>using namespacestd;#defineMAXN 2510#defineOO 0x3f3f3f3fintMAPS[MAXN][MAXN], DIST[MAXN], V[MAXN];CharSTR[MAXN][MAXN];intN;voidInit () { for(intI=1; i<=n; i++) for(intj=1; j<=n; J + +) { if(I==J) maps[i][j]=0; ElseMAPS[I][J] = maps[j][i]=Oo; }}intSolveintPintq) { intAns =0; for(intI=0; Str[p][i]; i++) if(Str[p][i]! =Str[q][i]) ans++; returnans;}voidDij () {memset (V,0,sizeof(v)); intsum =0; for(intI=1; i<=n; i++) Dist[i]= maps[1][i]; v[1] =1; for(intI=1; i<n; i++) { intIndex, mins=Oo; for(intj=1; j<=n; J + +) { if(!v[j] && dist[j]<mins) {Index=J; Mins=Dist[j]; }} sum+=mins; V[index]=1; for(intj=1; j<=n; J + +) { if(!v[j] && dist[j]>Maps[index][j]) {Dist[j]=Maps[index][j]; }}} printf ("The highest possible quality is 1/%d.\n", sum);}intMain () { while(SCANF ("%d", &N), N) { for(intI=1; I<=n; i++) scanf ("%s", Str[i]); Init (); for(intI=1; i<n; i++) { for(intj=i+1; j<=n; J + +) Maps[i][j]= Maps[j][i] =min (Solve (i, j), Maps[i][j]); } dij (); } return 0;}
View Code
Truck History POJ 1789