- 博客(14)
- 资源 (1)
- 收藏
- 关注
原创 POJ 3253 Fence Repair 哈夫曼树/优先级队列
题意:将一根长为l的木棍锯成n段,使l1+l2+l3+....= l, 且每次锯木棍所需花费等于木棍长度。求最小花费。 题解:学习优先级队列。 #include #include #include using namespace std; struct cmp { bool operator () ( const int &a, const int &b ) {
2011-07-31 17:32:38 969
转载 各种字符串hash函数比较
文章转摘自http://www.cmykrgb123.cn/blog/string-hash-compare/ 常用的字符串Hash函数还有ELFHash,APHash等等,都是十分简单有效的方法。这些函数使用位运算使得每一个字符都对最后的函数值产生影响。另外还有以MD5和SHA
2011-07-30 17:01:41 522
原创 POJ 2503 Babelfish hash / qsort+ bsearch
题意:先输入字典,然后查词。(以输入空格为界) 题解:别忘了字符串二分查找 #include #include using namespace std; #define prime 100003 struct Union { char eng[11], fore
2011-07-30 16:08:37 742
原创 POJ 2002 Squares hash/计算几何
题意: 给出一些坐标点,求出能构成的正方形的个数。 题解:此题也可用二分查找。 #include using namespace std; #define prime 9973 struct point { int x, y; } a[1010]; struct n
2011-07-30 11:26:52 662
原创 POJ 1840 Eqs hash
题意:解方程组a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,x属于[50,50]且x!=0输入a1,a2,a3,a4,a5,输出一共有多少种满足方程的解。 题解:左右分开,hash #include using namespace std; #
2011-07-28 22:47:10 581
原创 POJ 1936 All in All 字符串 水题
题意:没什么好说的,不过因为没看清题,输出大写的YES,NO,贡献了两次,泪流满面。函数strlen不要写在循环内就OK了。否则会耗去大半时间。 题解: #include using namespace std; #define N 100010 char str1[N]
2011-07-27 14:30:17 545
原创 POJ 3349 Snowflake Snow Snowflakes hash
题意:每个雪花有六个角,每个角用一个数字表示。输入n个雪花,若存在两个雪花相等则输出Twin snowflakes found。否则输出No two snowflakes are alike. 题解:hash #include #include using namespa
2011-07-27 11:11:59 615
原创 POJ 3080 Blue Jeans KMP
题意: 输入M个定长为60的DNA序列(字符串),求M条DNA的最长公共子序列,若有最长的公共子序列有若干条,则输出字典序最小的。 显然是一个字符串匹配问题。第一次用KMP算法。幸好看了严蔚敏老师的数据结构视频(第11,12),讲的很细。 题解:需要注意输出字典序最小的模式序
2011-07-26 21:58:03 531
原创 POJ 1611 The Suspects 并查集
题意:sars感染者呆过的每一个group的所有人都被认为是感染者,要求所有可能被感染的人数。 题解: 并查集 #include #include int father[30001], num[30001], r[30001]; /* 数组r表示秩的大小 */ int n,m; void make_set() { for ( int i = 0; i < n;
2011-07-24 21:26:51 488
原创 POJ 2524 Ubiquitous Religions 并查集
题意:给出一些数对,表示这两个人有相同的宗教信仰,现在要求人们信仰的宗教最多有多少种。 题解:并查集。 #include #include int father[50001],r[50001]; int m,n,res; void make_set () { for ( int i = 1; i <= n; i++ ) father[i] = i; mems
2011-07-24 14:38:41 535
原创 POJ 2352 Stars 树状数组
题意:有很多给定坐标的星星,求每个星星左下方的星星数。 题解:用树形数组解。因为输入时y是升序,只要x1 >= x2 就可行。所以可以将二维视作一维,只考虑x就可以了。另外需要注意的是,树形数组不能从0开始,否则函数lowbit,和函数update死循环。这个问题可以将输入的x平移一个单位(即加1)来解决。 #include #include int n, lev[16000
2011-07-23 22:17:19 490
原创 POJ 2299 Ultra-QuickSort 归并排序
题意:每次交换两个数,求排序所做的交换次数 题解:用归并排序求逆序数 #include int a[500000], b[500000]; long long cnt, n; void mergesort ( int l, int r ) { if ( l >= r ) return; int mid = ( l + r ) / 2; mergesort(
2011-07-23 11:53:56 493
原创 POJ 2388 Who's in the Middle 排序
题意:输出一串数字的中间数。 题解: #include using namespace std; void quiksort ( int * array, int left, int right ) { if ( left < right ) { int s = array [( left + right ) / 2]; int l = left
2011-07-21 23:46:57 628
原创 POJ 1035 Spell checker 字符串
#include using namespace std; string dic[10010]; string che[60]; int dc, cc, flag; void setFile () // 输入 { dc = cc = 0; do { dc++; cin >> dic[dc]; } while ( dc <= 10000 && dic[d
2011-07-20 16:59:17 534
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人