poj1789 Truck History
来源:互联网 发布:鲁荣渔2682惨案 知乎 编辑:程序博客网 时间:2024/06/05 11:20
链接:http://poj.org/problem?id=1789
题意: 这个题的题意看英文那真的怎么也看不懂啊。哎,只能说英文水准还不够啊。关键的一句:They defined the distance of truck types as the number of positions with different letters in truck type codes. (看不懂这句,这题就没法做。)关键意思是说:distance定义为两个卡车code之间每个相同位置letter不同的个数。例如:aaaaaaa和abcdefg的distance为6。懂了这个题目就好做了。题目本身很简单。
用prim就可以过了,适合像我这样的新手入门。最好再把kruskal的写一遍。这样就好了。
浅谈:略。
题意: 这个题的题意看英文那真的怎么也看不懂啊。哎,只能说英文水准还不够啊。关键的一句:They defined the distance of truck types as the number of positions with different letters in truck type codes. (看不懂这句,这题就没法做。)关键意思是说:distance定义为两个卡车code之间每个相同位置letter不同的个数。例如:aaaaaaa和abcdefg的distance为6。懂了这个题目就好做了。题目本身很简单。
用prim就可以过了,适合像我这样的新手入门。最好再把kruskal的写一遍。这样就好了。
浅谈:略。
#include<iostream>#include<cstring>#define MAX 2010#define MAXdis 10using namespace std;struct truck{ char code[8];};truck tr[MAX];int lowcost[MAX];int closest[MAX];int N;int check(int m,int n){ if(m==n)return 0; int i,differ=0; for(i=0;i<7;i++)if(tr[m].code[i]!=tr[n].code[i])differ++; return differ;}int Prim(){ int i,j,mindis,minone; int ans=0; for(i=1;i<=N;i++) { lowcost[i]=check(1,i);closest[i]=1; } for(i=0;i<N-1;i++) { mindis=MAXdis; for(j=1;j<=N;j++) if(lowcost[j]&&mindis>lowcost[j]) { mindis=lowcost[j]; minone=j; } ans+=lowcost[minone]; lowcost[minone]=0; for(j=1;j<=N;j++) {int differ=check(j,minone);if(differ<lowcost[j]){ lowcost[j]=differ; closest[j]=minone;} } } return ans;}int main(){int n,i;char code[8];while(cin>>n&&n){ N=n; for(i=1;i<=n;i++) { cin>>code;strcpy(tr[i].code,code); } cout<<"The highest possible quality is 1/"<<Prim(); cout<<"."<<endl;} return 0;}
- POJ1789 Truck History
- Truck History(POJ1789)
- poj1789 - Truck History
- Truck History poj1789
- poj1789 Truck History
- poj1789--Truck History
- poj1789 Truck History
- poj1789 Truck History(Prim)
- POJ1789 Truck History【Prim】
- POJ1789--Truck History
- poj1789 Truck History
- POJ1789 Truck History
- POJ1789 Truck History
- POJ1789-Truck History .
- POJ1789 Truck History
- POJ1789 Truck History
- POJ1789 Truck History
- POJ1789 Truck History
- LeetCode Median of Two Sorted Arrays
- CE 使用
- OpenNI1.x 和 OpenNI2.x的区别
- Java事件机制
- phpmyadmin 开放远程登录的权限
- poj1789 Truck History
- 在论坛中出现的比较难的sql问题:16(取一个字段中的数字)
- poj2253 Frogger
- 值得纪念、值得回忆的2014校招
- 使用DUMP数据块与BBED查看BLOCK对比数据库修改时的SCN
- 大学是什么
- poj3041 Asteroids
- Sample 3.10:arith.cpp
- Java基础 Java 中 equals 和 hashCode