Stanford 算法入门 week 6 Bloom Filter, Hash Function, Search Tree
来源:互联网 发布:网络主题团日活动 编辑:程序博客网 时间:2024/05/16 16:54
Bloom Filter 讲解:http://blog.csdn.net/jiaomeng/article/details/1495500
-----------------------------------------------------------------------------------------------------------------------
Programming Question - 6
-----------------------------------------------------------------------------------------------------------------------第一题的代码
#include <iostream>#include <fstream>#define MAX 1000000#define MIN 4000using namespace std;int hash[MIN + 1] = { 0 };int count = 0;void readData() {ifstream fin("HashInt.txt");int temp = 0;while(fin>>temp) {if(temp < MIN) hash[temp]++;}}bool hashMap(int n) {if(n > MIN) return false;if(hash[n]) return true;else return false;}int main() {readData();for(int i = 2500; i <= 4000; i++) {for(int j = 1; j <= (i - 1) / 2; j++) {if(hashMap(j) && hashMap(i - j)) {count++;break;}}}cout<<count<<endl;return 0;}
第二题的思路:http://www.cnblogs.com/lienhua34/archive/2011/12/06/2381299.html
利用大顶堆+小顶堆的方法应该是最高效的
main.cpp的代码, 我的“heap.h”用到的是这里的 http://blog.csdn.net/neostar2008/article/details/7769058
#include <iostream>#include <vector>#include <fstream>#include "heap.h"using namespace std;int main() {ifstream fin("Median.txt");MaxHeap maxh;MinHeap minh;int medianSum = 0;int temp;while(fin>>temp) {if(temp < maxh.top()) maxh.insert(temp);else minh.insert(temp);if(maxh.heapSize() - minh.heapSize() > 1) {minh.insert(maxh.extractMax());}if(minh.heapSize() > maxh.heapSize()) {maxh.insert(minh.extractMin());}medianSum += maxh.top();}cout<<medianSum % 10000<<endl;return 0;}
- Stanford 算法入门 week 6 Bloom Filter, Hash Function, Search Tree
- Stanford 算法入门 week 2 Assignment QuickSort
- Stanford 算法入门 week 3 Assignment
- Hash和Bloom Filter
- Hash和Bloom Filter
- Hash和Bloom Filter
- Hash和Bloom Filter
- Hash与Bloom Filter
- stanford 算法 week 5
- Bloom Filter 主流Hash散列算法介绍
- Stanford 算法入门 Week 4 Graph,BFS,DFS, partial_sort
- Stanford 算法入门 week 5 dijkstra 及其堆优化 stringstream
- 各种hash,bloom filter 集锦
- Bloom Filter 系列改进之Bloom Tree
- Bloom filter算法简介
- Bloom Filter算法
- bloom filter算法
- Bloom-Filter算法
- hdu 1754 I Hate It (线段树)
- iOS的基本设计模式
- JSF 2.0简介:Ajax对页面的增加与删除操作例子
- poj2752 Seek the Name, Seek the Fame (串)
- patchGuard v2
- Stanford 算法入门 week 6 Bloom Filter, Hash Function, Search Tree
- hdu1233 还是畅通工程 ( 最小生成树)
- svn版本控制系统在CentOS上的部署
- hdu1874 畅通工程续 (最短路)
- 网络整合营销之策略
- hdu1596 最短路
- ACM中使用JAVA
- 简单动态规划——电路布线
- 计算几何题目列表——第三章之群魔乱舞