LeeBlog

导航

随笔分类 -  最小生成树

HDU 1233 还是畅通工程
摘要:这题是一个最小生成树,用kustra做,在给结构体排序时要用快排,不能冒泡,否则超时,这里有我冒泡的代码,你可以提交试试#include<stdio.h>#include<stdlib.h>int set[105],n,m,sum;struct e{ int x,y,v;}val[10000];int cmp( const void *a,const void *b ){ return ( ( e * )a )-> v - ( ( e * )b ) ->v;}int find( int x ){ return x == set[x] ? x : set[x] 阅读全文

posted @ 2011-05-02 13:35 LeeBlog 阅读(184) 评论(0) 推荐(0)

HDU 1879 继续畅通工程
摘要:跟畅通工程差不多,我的代码就在那上面改的#include<stdio.h>#include<stdlib.h>struct e{ int x,y,v;}val[10500];int n,m,set[105],sum;int cmp( const void *a,const void *b ){ return ( ( e * )a ) -> v - ( ( e * )b ) -> v;}int find( int i ){ return i == set[i] ? i :set[i] = find( set[i] );}void Kustra( ){ for( 阅读全文

posted @ 2011-04-30 09:02 LeeBlog 阅读(158) 评论(0) 推荐(0)

hdu 1875 畅通工程再续
摘要:这是我第二次敲这个题,没想到果断悲剧了,最后只能翻出以前的代码,没想到是qsort出问题了,以后qsort全部用问号表达式,不再用a-b了.#include<stdio.h>#include<math.h>#include<stdlib.h>int set[105],t,c,m;double sum = 0;struct e{ int x,y; double v;}val[10000];struct coor{ int x,y;}co[105];int cmp( const void *a,const void *b ){ return ((e *)a) - 阅读全文

posted @ 2011-02-27 19:45 LeeBlog 阅读(367) 评论(0) 推荐(0)