zoj 2326
来源:互联网 发布:关于人工智能的弊端 编辑:程序博客网 时间:2024/05/29 11:15
最小生成树题目……
#include<stdio.h>#include<stdlib.h>#include<string.h>struct paths{char x[21];char y[21];float dis;}path[400];int cmp(const void *a,const void *b) //这里注意啦,qsort返回值是int型的,必然不能返回两数的差值!!!{return (*(struct paths*)a).dis>(*(struct paths*)b).dis?1:-1;}int find(int x,int *father){if(father[x]==x)return x;elsereturn find(father[x],father);}int main(){int m,n,j,father[400],i,A,B;char a[400][21];float len,count;scanf("%f",&len);scanf("%d",&n);for(i=0;i<n;i++)scanf("%s",a[i]);for(i=0;i<n;i++)father[i]=i;scanf("%d",&m);for(i=0;i<m;i++)scanf("%s%s%f",&path[i].x,&path[i].y,&path[i].dis);qsort(path,m,sizeof(path[0]),cmp);for(i=0,count=0;i<m;i++){for(j=0;j<n&&strcmp(a[j],path[i].x)!=0;j++){}A=find(j,father);for(j=0;j<n&&strcmp(a[j],path[i].y)!=0;j++){}B=find(j,father);if(A!=B){father[A]=B;count+=path[i].dis;}}if(count<=len)printf("Need %.1f miles of cable\n",count);elseprintf("Not enough cable\n");return 0;}
- zoj 2326
- zoj 2326
- zoj 2326
- ZOJ-2326
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- 什么是Y4M文件格式
- 到底该如何学习数据结构?
- Oracle、Sql Server数据库服务器新增监听端口
- 网络等待indicator的界面设置
- 周工作总结
- zoj 2326
- Jboss 6.0.0-Fina 报java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11Graphic解决
- sql 与pgsql
- 磁盘存储原理
- zoj 3321
- perl docs:简简单单讲map
- java 使用log4j写日志文件
- __ieee80211_data_to_8023
- Spring注解@Component、@Repository、@Service、@Controller区别