POJ 1789-truck History

Source: Internet
Author: User

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

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.