POJ 1789-Truck History
来源:互联网 发布:京九直通车知乎 编辑:程序博客网 时间:2024/06/05 07:08
题目链接:Truck History
题意就是N个卡车的型号,一代一代的发展,两辆卡车的型号中 不同字母的个数代表着两辆卡车的距离,确定一个点,遍历到所有的点,使之这个距离最小。
很明显最小生成树,稠密图,1次AC,水过
PS:厚颜无耻的先看了Discuss才做的,否则我也漏“.”,罪过罪过
#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];char 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) mapp[i][j] = 0; else mapp[i][j] = SUM(i,j); } } Prim(); cout<<"The highest possible quality is 1/"<<ans<<'.'<<endl; } return 0;}
0 0
- POJ 1789 Truck History
- POJ 1789 Truck History
- POJ 1789 Truck History
- poj 1789 Truck History
- poj 1789 Truck History
- Poj 1789 Truck History
- poj 1789 Truck History
- poj 1789 Truck History
- poj 1789 Truck History
- poj 1789 Truck History
- POJ-1789-Truck History
- poj-1789-Truck History
- POJ 1789 Truck History
- poj 1789 Truck History
- POJ 1789 Truck History
- POJ 1789 Truck History
- POJ 1789 Truck History
- POJ 1789 Truck History
- NDK/JNI学习--导入hello-jni工程
- DB2 配置
- unicode ascii 互转 函数 C实现
- 【C语言复习(十二)】数组基础
- Android 3D游戏基础介绍
- POJ 1789-Truck History
- 大写文件夹名和.c和.h文件名
- C# 网页放大缩小(WebBrowser && AxWebBrowser)
- error: The requested URL returned error: 403 while accessing https://jacsice@github.com/jacsice/hous
- 匿名内部类访问外部类中的局部变量必须是final属性
- linux 下安装 openresty-1.7.0.1
- PAT Advanced Level 1051
- Jquery+HTML+CSS运用
- Ehcache详细解读