Truck History POJ 1789

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.