摘要:
/** 最小生成树,(kruskal) * 本题要点:当两点之间已有路时,把这两点的路长设为0,然后就是套用kruskal了 */#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int M = 5050;int p[M];struct edge {//边节点 int a; int b; int w;}e[M];int cmp(const void *a, const void *b) {//按权值从小到大排序 return (*(edge *)a) 阅读全文
posted @ 2012-04-09 22:57
Try86
阅读(568)
评论(0)
推荐(0)
摘要:
/** 最小生成树练手题,采用kruskal求解 */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int M = 5050;int p[M];struct edge {//边节点 int a; int b; int w;}e[M];int cmp(const void *a, const void *b) {//按权值从小到大排序 return (*(edge *)a).w - (*(edge * 阅读全文
posted @ 2012-04-09 22:15
Try86
阅读(195)
评论(0)
推荐(0)
摘要:
/** hash+数学,很好的题 * 对整数求hash,采用除余法,及线性探测解决冲突 * 注意:devc++中不能定义全局变量count,它和库函数中的函数名同名了 */#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int M = 175447;int counts[M];int result[M];int temp[101];int hashInt(int s) { int k = s % M; if (k < 0) k += M; w 阅读全文
posted @ 2012-04-09 21:05
Try86
阅读(245)
评论(0)
推荐(0)
摘要:
/** hash*/#include <cstdio>#include <climits>#include <cstring>#include <iostream>using namespace std;const int M = 1000001;bool hash[M];void init() { for (int i=0; i<M; ++i) hash[i] = false; return ; }int main() { int n, m, maxm; while (scanf("%d%d", &n, &am 阅读全文
posted @ 2012-04-09 19:54
Try86
阅读(219)
评论(0)
推荐(0)
摘要:
/** 分析:题意要求找字符串个数最多的一个* 方法:很多,hash就是其中一种 * 注意两点:1.去掉前导0; 2.每组测试数据后,要释放内存 * 第一点解析:例如数据01,001,0001, 00001不去前导0的话,hash以后映射到不同的表位置 *//* Author: Try86 Date: 09/04/12 18:01*/#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int M = 5471; //hash表大小struct node 阅读全文
posted @ 2012-04-09 18:37
Try86
阅读(559)
评论(0)
推荐(0)
摘要:
//字符串hash练手题,采用拉链式解决冲突 #include <cstdio>#include <cstring>#include <iostream>using namespace std;const int M = 43853;//hash表大小 struct node {//节点 char str1[11]; char str2[11]; node *next; };struct hashTable {//hash表 node *link;}hash[M];char text[3005];char str1[11], str2[11], ch[11] 阅读全文
posted @ 2012-04-09 17:49
Try86
阅读(162)
评论(0)
推荐(0)