POJ 1789 、Truck History
来源:互联网 发布:信封设计软件 编辑:程序博客网 时间:2024/06/05 07:49
prim最小生成树模板,直接上代码
/*poj 178916004K344MS*/#include<cstdio>#include<iostream>#include<cstring>#define MAXN 2005using namespace std;int n,gra[MAXN][MAXN],low_cost[MAXN];char str[MAXN][8];void init(){for(int i = 1;i <= n;i ++){for(int j = i + 1;j <= n;j ++){int cnt = 0;for(int k = 0;k < 7;k ++)cnt += (str[i][k] != str[j][k]);gra[i][j] = gra[j][i] = cnt;}}for(int i = 1;i <= n;i ++)low_cost[i] = 0xfffffff;}int calc(){bool mark[MAXN] = {false};int sum = 0,s = 1,m = 1,tmin = 0xfffffff,ti = 0;mark[s] = true;while(m < n){tmin = 0xfffffff; ti = 0;for(int i = 2;i <= n;i ++){if(!mark[i] && low_cost[i] > gra[s][i])low_cost[i] = gra[s][i];if(!mark[i] && tmin > low_cost[i]){tmin = low_cost[i];ti = i;}}s = ti;mark[s] = true;sum += tmin;m ++;}return sum;}int main(){while(cin>>n && n){memset(gra , 0 , sizeof(gra));memset(low_cost , 0 , sizeof(low_cost));for(int i = 1;i <= n;i ++)scanf("%s",str[i]);init();printf("The highest possible quality is 1/%d.\n",calc());}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
- lamp 的php安装位置
- ado.net中的DataSet使用
- javascript常用属性
- KEIL编译错误信息表
- BlueTooth: 蓝牙Bluz协议栈概述
- POJ 1789 、Truck History
- 中国计算机学会推荐国际学术刊物
- 一道JAVA IO面试题
- oracle 下分页查询,与树形结构Sql 写法
- hdu 3602 2012
- Next Permutation :from LeetCode
- PJOI 1024 Hamilton Circles 矩阵快速幂
- 生活不应将就
- iOS企业ipa(299)证书制作、打包发布全流程