Title Link: Truck History
Test instructions is the model of n trucks, the development of a generation, two truck models in the number of different letters represents the distance of two trucks, determine a point. Traverse to the full point to make it the smallest distance.
Very obvious minimum spanning tree, dense graph. 1 times AC, water over
PS: Brazen first looked at the discuss to do, otherwise I also miss "." Sins and sins
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < algorithm>const int N = 2001;const int INF = 1e8;using namespace Std;int mapp[n][n];int n,ans;int dis[n];bool vis[N];ch AR a[n][8];void init () {memset (vis,0,sizeof (VIS)); memset (dis,0,sizeof (DIS));} int sum (int x,int y) {int sum = 0; for (int i = 0;i<7;i++) {if (a[x][i]!=a[y][i]) sum++; } return sum;} void Prim () {ans = 0; int Pos,minn; for (int i = 0;i<n;i++) dis[i] = Mapp[0][i]; Vis[0] = true; for (int i = 0;i<n;i++) {minn = INF; for (int j = 0;j<n;j++) {if (!vis[j] && dis[j]<minn) {pos = j; Minn = dis[j]; }} if (minn!=inf) ans + = Minn; Vis[pos] = true; for (int j = 0;j<n;j++) {if (!vis[j] && dis[j] > Mapp[pos][j]) dis[j] = Mapp [POS][J]; }}}int Main () {while (Cin>>n && N) {init (); for (int i = 0;i<n;i++) cin>>a[i]; int i,j; for (i = 0;i<n;i++) {for (j = 0;j<n;j++) {if (i==j) m APP[I][J] = 0; else mapp[i][j] = SUM (I,J); }} Prim (); cout<< "The highest possible quality is 1/' <<ans<< '. ' <<endl; } return 0;}
POJ 1789-truck History