poj1789
来源:互联网 发布:熟悉linux内核 编辑:程序博客网 时间:2024/05/21 17:42
/*
分析:
最小生成树。
构建关系,暴力求解吧。
2012-07-31 10:44
*/
分析:
最小生成树。
构建关系,暴力求解吧。
2012-07-31 10:44
*/
#include"stdio.h"#include"string.h"#include"stdlib.h"int n;char str[2011][10];int set[2011];struct A{int a,b;int len;}eage[2005555];int num_eage;int cmp(const void *a,const void *b){struct A *c,*d;c=(struct A *)a;d=(struct A *)b;return c->len-d->len;}void build(int num){int i;for(i=0;i<num;i++)set[i]=i;}int find(int k){if(set[k]==k)return k;set[k]=find(set[k]);return set[k];}void Union(int f1,int f2){set[f1]=f2;}int Kruskal(){int i;int ans;int count;int f1,f2;ans=0;count=1;for(i=0;i<num_eage;i++){if(count==n)break;f1=find(eage[i].a);f2=find(eage[i].b);if(f1==f2)continue;ans+=eage[i].len;Union(f1,f2);count++;}return ans;}int main(){int i,l,j;int temp;while(scanf("%d",&n),n){build(n);num_eage=0;for(i=0;i<n;i++){scanf("%s",str[i]);for(l=0;l<i;l++){eage[num_eage].a=i;eage[num_eage].b=l;temp=0;for(j=0;j<7;j++)if(str[i][j]!=str[l][j])temp++;eage[num_eage++].len=temp;}}qsort(eage,num_eage,sizeof(eage[0]),cmp);printf("The highest possible quality is 1/%d.\n",Kruskal());}return 0;}
- poj1789
- poj1789
- poj1789
- poj1789
- poj1789
- POJ1789
- poj1789
- poj1789
- poj1789
- poj1789
- POJ1789
- POJ1789
- poj1789
- poj1789 Prim
- poj1789--prim
- poj1789(prim)
- prim poj1789
- poj1789 prim
- Zynga:一场近50亿的游戏
- Chapter 5 初始化与清理
- C++中extern解析
- 使用clearcase时,突然断电了,该怎么办?
- 西宁归来
- poj1789
- 二叉树的建立与遍历
- mysql权限说明
- 详谈 UNIX 环境进程异常退出
- CHtmlView类
- 破解的(可以让思科设备识别的)模块
- yuv420P数据对AVFrame的赋值
- CGBitmapContextCreate函数参数详解
- Menu Redirect Prompt when developing in JSF+Primefaces +JQuery