LeeBlog

导航

02 2011 档案

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 阅读(371) 评论(0) 推荐(0)

hdu 1856 More is better
摘要:这题分为四个步骤 压缩,合并完全,压缩查找最大集合include<stdio.h>int set[10000000],count[10000000];int find( int x ){ return set[ x ] == x ? x : set[ x ] = find( set[ x ] );} void merge( int x,int y ){ int a = find( x ),b = find( y ); set[ a ] = b; }int main( ){ int n,i,a,b; while( scanf( "%d",&n ) !=EO 阅读全文

posted @ 2011-02-26 09:55 LeeBlog 阅读(164) 评论(0) 推荐(0)

hdu 1213 How Many Tables
摘要:并查集基础#include<stdio.h>int set[100000];int find( int i ){ return set[ i ] == i ? i : set[ i ] = find( set[ i ] );//路径压缩}//查找跟结点void merge( int x,int y ){ int a = find( x ), b = find( y ); if( a != b ) set[ a ] = b;//合并 }int main( ){ int T,n,m,a,b; scanf( "%d",&T ); while( T-- ) { 阅读全文

posted @ 2011-02-26 09:48 LeeBlog 阅读(144) 评论(0) 推荐(0)

hdu 1232 畅通工程
摘要:这题就是把所有的村庄看它们是否畅通来分成n个集合,然后只要修建 n - 1 条道路就可以把他们连起来了#include<stdio.h>int set[ 1024 ];int find( int i ){ return set[ i ] == i ? i : set[ i ] = find( set[ i ] );}void merge( int x, int y ){ int a = find( x ),b = find( y ); set[ a ] = b; }int main( ){ int n,m,a,b; while( scanf( "%d",& 阅读全文

posted @ 2011-02-26 09:39 LeeBlog 阅读(171) 评论(0) 推荐(0)

hdu 1863 畅通工程
摘要:这题是刚学最小生成树的一入门题,其实就是求最小生成树,用结构体定义这棵树,到时候便于权值排序,输入后进行排序,让后再讲这些顶点连成一个集合,并在这过程中把各权值相加(因为这些权值已按递增排列,所以得出的集合时权值最小的),至于是否能保证畅通则只要看有几个根结点就可以了#include<stdio.h>#include<stdlib.h>#include<string.h>int set[1000],n,m,x,y,val;struct Ed{ int x,y,val; }e[10000];int cmp( const void *a,const void * 阅读全文

posted @ 2011-02-26 09:34 LeeBlog 阅读(224) 评论(0) 推荐(0)

hdu 2028 Lowest Common Multiple Plus 求最小公倍数
摘要:此题思路较简单,经多方分析后可得,两数的最小公倍数即为两数之积除以两数的最大公约数( 可用辗转相除法做,这里偷了以下懒),此题我采用的方法是先求两个两个一求,最后全部求出,还有记得用64位存贮,不然会WA的……#include<stdio.h>void cal( int n ){ long long a,i,b = 1; while( n-- ) { scanf( "%I64d",&a ); for( i = a < b ? a : b;; --i ) { if( a % i == 0 && b % i == 0 ) break; 阅读全文

posted @ 2011-02-24 16:44 LeeBlog 阅读(360) 评论(0) 推荐(0)

杭电ACM题目分类
摘要:杭电ACM题目分类基础题:1000、1001、1004、1005、1008、1012、1013、1014、1017、1019、1021、1028、1029、1032、1037、1040、1048、1056、1058、1061、1070、1076、1089、1090、1091、1092、1093、1094、1095、1096、1097、1098、1106、1108、1157、1163、1164、1170、1194、1196、1197、1201、1202、1205、1219、1234、1235、1236、1248、1266、1279、1282、1283、1302、1303、1323、1326、13 阅读全文

posted @ 2011-02-01 16:46 LeeBlog 阅读(1337) 评论(0) 推荐(0)

Poj题目归类
摘要:Poj题目归类poj--题目分类1、排序1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376, 2377, 2380,1318, 1877, 1928, 1971, 1974, 1990, 2001, 2002, 2092, 2379,1002(需要字符处理,排序用快排即可) 1007(稳定的排序) 2159(题意较难懂)2231 2371(简单排序) 2388(顺序统计算法) 2418(二*排序树)2、搜索、回溯、遍历1022 1111 1118 1129 1190 1562 1564 1573 1655 2184 阅读全文

posted @ 2011-02-01 16:45 LeeBlog 阅读(450) 评论(0) 推荐(0)

HDU 2092 整数解
摘要:剪花布条Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2457Accepted Submission(s): 1635Problem Description一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?Input输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少 阅读全文

posted @ 2011-02-01 12:38 LeeBlog 阅读(884) 评论(0) 推荐(0)

HDU 2087剪花布条 KMP
摘要:KMP算法入门题 哥第一次写KMP惭愧啊,惭愧getnext写得蛋痛,后面的KMP部分更蛋痛。改了N久#include<stdio.h>#include<string.h>#define Max 1005char str[Max+5] = {0},ch[Max+5] = {0};int next[Max+5],count = 0,n;void getnext( ){ int i = 0,j = -1; next[0] = -1; while( ch[i] ) { if( j == -1 || ch[i] == ch[j] ) ++i,++j,next[i] = j; e 阅读全文

posted @ 2011-02-01 12:22 LeeBlog 阅读(259) 评论(0) 推荐(0)