Apriori算法原理:http://blog.csdn.net/kingzone_2008/article/details/8183768

  1. import java.util.HashMap;
  2. import java.util.HashSet;
  3. import java.util.Iterator;
  4. import java.util.Map;
  5. import java.util.Set;
  6. import java.util.TreeMap;
  7. /**
  8. * <B>关联规则挖掘:Apriori算法</B>
  9. *
  10. * <P>按照Apriori算法的基本思想来实现
  11. *
  12. * @author king
  13. * @since 2013/06/27
  14. *
  15. */
  16. public class Apriori {
  17. private Map<Integer, Set<String>> txDatabase; // 事务数据库
  18. private Float minSup; // 最小支持度
  19. private Float minConf; // 最小置信度
  20. private Integer txDatabaseCount; // 事务数据库中的事务数
  21.  
  22. private Map<Integer, Set<Set<String>>> freqItemSet; // 频繁项集集合
  23. private Map<Set<String>, Set<Set<String>>> assiciationRules; // 频繁关联规则集合
  24.  
  25. public Apriori(
  26. Map<Integer, Set<String>> txDatabase,
  27. Float minSup,
  28. Float minConf) {
  29. this.txDatabase = txDatabase;
  30. this.minSup = minSup;
  31. this.minConf = minConf;
  32. this.txDatabaseCount = this.txDatabase.size();
  33. freqItemSet = new TreeMap<Integer, Set<Set<String>>>();
  34. assiciationRules = new HashMap<Set<String>, Set<Set<String>>>();
  35. }
  36.  
  37. /**
  38. * 扫描事务数据库,计算频繁1-项集
  39. * @return
  40. */
  41. public Map<Set<String>, Float> getFreq1ItemSet() {
  42. Map<Set<String>, Float> freq1ItemSetMap = new HashMap<Set<String>, Float>();
  43. Map<Set<String>, Integer> candFreq1ItemSet = this.getCandFreq1ItemSet();
  44. Iterator<Map.Entry<Set<String>, Integer>> it = candFreq1ItemSet.entrySet().iterator();
  45. while(it.hasNext()) {
  46. Map.Entry<Set<String>, Integer> entry = it.next();
  47. // 计算支持度
  48. Float supported = new Float(entry.getValue().toString())/new Float(txDatabaseCount);
  49. if(supported>=minSup) {
  50. freq1ItemSetMap.put(entry.getKey(), supported);
  51. }
  52. }
  53. return freq1ItemSetMap;
  54. }
  55.  
  56. /**
  57. * 计算候选频繁1-项集
  58. * @return
  59. */
  60. public Map<Set<String>, Integer> getCandFreq1ItemSet() {
  61. Map<Set<String>, Integer> candFreq1ItemSetMap = new HashMap<Set<String>, Integer>();
  62. Iterator<Map.Entry<Integer, Set<String>>> it = txDatabase.entrySet().iterator();
  63. // 统计支持数,生成候选频繁1-项集
  64. while(it.hasNext()) {
  65. Map.Entry<Integer, Set<String>> entry = it.next();
  66. Set<String> itemSet = entry.getValue();
  67. for(String item : itemSet) {
  68. Set<String> key = new HashSet<String>();
  69. key.add(item.trim());
  70. if(!candFreq1ItemSetMap.containsKey(key)) {
  71. Integer value = 1;
  72. candFreq1ItemSetMap.put(key, value);
  73. }
  74. else {
  75. Integer value = 1+candFreq1ItemSetMap.get(key);
  76. candFreq1ItemSetMap.put(key, value);
  77. }
  78. }
  79. }
  80. return candFreq1ItemSetMap;
  81. }
  82.  
  83. /**
  84. * 根据频繁(k-1)-项集计算候选频繁k-项集
  85. *
  86. * @param m 其中m=k-1
  87. * @param freqMItemSet 频繁(k-1)-项集
  88. * @return
  89. */
  90. public Set<Set<String>> aprioriGen(int m, Set<Set<String>> freqMItemSet) {
  91. Set<Set<String>> candFreqKItemSet = new HashSet<Set<String>>();
  92. Iterator<Set<String>> it = freqMItemSet.iterator();
  93. Set<String> originalItemSet = null;
  94. while(it.hasNext()) {
  95. originalItemSet = it.next();
  96. Iterator<Set<String>> itr = this.getIterator(originalItemSet, freqMItemSet);
  97. while(itr.hasNext()) {
  98. Set<String> identicalSet = new HashSet<String>(); // 两个项集相同元素的集合(集合的交运算)
  99. identicalSet.addAll(originalItemSet);
  100. Set<String> set = itr.next();
  101. identicalSet.retainAll(set); // identicalSet中剩下的元素是identicalSet与set集合中公有的元素
  102. if(identicalSet.size() == m-1) { // (k-1)-项集中k-2个相同
  103. Set<String> differentSet = new HashSet<String>(); // 两个项集不同元素的集合(集合的差运算)
  104. differentSet.addAll(originalItemSet);
  105. differentSet.removeAll(set); // 因为有k-2个相同,则differentSet中一定剩下一个元素,即differentSet大小为1
  106. differentSet.addAll(set); // 构造候选k-项集的一个元素(set大小为k-1,differentSet大小为k)
  107. if(!this.has_infrequent_subset(differentSet, freqMItemSet))
  108. candFreqKItemSet.add(differentSet); // 加入候选k-项集集合
  109. }
  110. }
  111. }
  112. return candFreqKItemSet;
  113. }
  114.  
  115. /**
  116. * 使用先验知识,剪枝。若候选k项集中存在k-1项子集不是频繁k-1项集,则删除该候选k项集
  117. * @param candKItemSet
  118. * @param freqMItemSet
  119. * @return
  120. */
  121. private boolean has_infrequent_subset(Set<String> candKItemSet, Set<Set<String>> freqMItemSet) {
  122. Set<String> tempSet = new HashSet<String>();
  123. tempSet.addAll(candKItemSet);
  124. Iterator<String> itItem = candKItemSet.iterator();
  125. while(itItem.hasNext()) {
  126. String item = itItem.next();
  127. tempSet.remove(item);// 该候选去掉一项后变为k-1项集
  128. if(!freqMItemSet.contains(tempSet))// 判断k-1项集是否是频繁项集
  129. return true;
  130. tempSet.add(item);// 恢复
  131. }
  132. return false;
  133. }
  134.  
  135. /**
  136. * 根据一个频繁k-项集的元素(集合),获取到频繁k-项集的从该元素开始的迭代器实例
  137. * @param itemSet
  138. * @param freqKItemSet 频繁k-项集
  139. * @return
  140. */
  141. private Iterator<Set<String>> getIterator(Set<String> itemSet, Set<Set<String>> freqKItemSet) {
  142. Iterator<Set<String>> it = freqKItemSet.iterator();
  143. while(it.hasNext()) {
  144. if(itemSet.equals(it.next())) {
  145. break;
  146. }
  147. }
  148. return it;
  149. }
  150.  
  151. /**
  152. * 根据频繁(k-1)-项集,调用aprioriGen方法,计算频繁k-项集
  153. *
  154. * @param k
  155. * @param freqMItemSet 频繁(k-1)-项集
  156. * @return
  157. */
  158. public Map<Set<String>, Float> getFreqKItemSet(int k, Set<Set<String>> freqMItemSet) {
  159. Map<Set<String>, Integer> candFreqKItemSetMap = new HashMap<Set<String>, Integer>();
  160. // 调用aprioriGen方法,得到候选频繁k-项集
  161. Set<Set<String>> candFreqKItemSet = this.aprioriGen(k-1, freqMItemSet);
  162.  
  163. // 扫描事务数据库
  164. Iterator<Map.Entry<Integer, Set<String>>> it = txDatabase.entrySet().iterator();
  165. // 统计支持数
  166. while(it.hasNext()) {
  167. Map.Entry<Integer, Set<String>> entry = it.next();
  168. Iterator<Set<String>> kit = candFreqKItemSet.iterator();
  169. while(kit.hasNext()) {
  170. Set<String> kSet = kit.next();
  171. Set<String> set = new HashSet<String>();
  172. set.addAll(kSet);
  173. set.removeAll(entry.getValue()); // 候选频繁k-项集与事务数据库中元素做差运算
  174. if(set.isEmpty()) { // 如果拷贝set为空,支持数加1
  175. if(candFreqKItemSetMap.get(kSet) == null) {
  176. Integer value = 1;
  177. candFreqKItemSetMap.put(kSet, value);
  178. }
  179. else {
  180. Integer value = 1+candFreqKItemSetMap.get(kSet);
  181. candFreqKItemSetMap.put(kSet, value);
  182. }
  183. }
  184. }
  185. }
  186. // 计算支持度,生成频繁k-项集,并返回
  187. return support(candFreqKItemSetMap);
  188. }
  189.  
  190. /**
  191. * 根据候选频繁k-项集,得到频繁k-项集
  192. *
  193. * @param candFreqKItemSetMap 候选k项集(包含支持计数)
  194. * @return freqKItemSetMap 频繁k项集及其支持度(比例)
  195. */
  196. public Map<Set<String>, Float> support(Map<Set<String>, Integer> candFreqKItemSetMap) {
  197. Map<Set<String>, Float> freqKItemSetMap = new HashMap<Set<String>, Float>();
  198. Iterator<Map.Entry<Set<String>, Integer>> it = candFreqKItemSetMap.entrySet().iterator();
  199. while(it.hasNext()) {
  200. Map.Entry<Set<String>, Integer> entry = it.next();
  201. // 计算支持度
  202. Float supportRate = new Float(entry.getValue().toString())/new Float(txDatabaseCount);
  203. if(supportRate<minSup) { // 如果不满足最小支持度,删除
  204. it.remove();
  205. }
  206. else {
  207. freqKItemSetMap.put(entry.getKey(), supportRate);
  208. }
  209. }
  210. return freqKItemSetMap;
  211. }
  212.  
  213. /**
  214. * 挖掘全部频繁项集
  215. */
  216. public void mineFreqItemSet() {
  217. // 计算频繁1-项集
  218. Set<Set<String>> freqKItemSet = this.getFreq1ItemSet().keySet();
  219. freqItemSet.put(1, freqKItemSet);
  220. // 计算频繁k-项集(k>1)
  221. int k = 2;
  222. while(true) {
  223. Map<Set<String>, Float> freqKItemSetMap = this.getFreqKItemSet(k, freqKItemSet);
  224. if(!freqKItemSetMap.isEmpty()) {
  225. this.freqItemSet.put(k, freqKItemSetMap.keySet());
  226. freqKItemSet = freqKItemSetMap.keySet();
  227. }
  228. else {
  229. break;
  230. }
  231. k++;
  232. }
  233. }
  234.  
  235. /**
  236. * <P>挖掘频繁关联规则
  237. * <P>首先挖掘出全部的频繁项集,在此基础上挖掘频繁关联规则
  238. */
  239. public void mineAssociationRules() {
  240. freqItemSet.remove(1); // 删除频繁1-项集
  241. Iterator<Map.Entry<Integer, Set<Set<String>>>> it = freqItemSet.entrySet().iterator();
  242. while(it.hasNext()) {
  243. Map.Entry<Integer, Set<Set<String>>> entry = it.next();
  244. for(Set<String> itemSet : entry.getValue()) {
  245. // 对每个频繁项集进行关联规则的挖掘
  246. mine(itemSet);
  247. }
  248. }
  249. }
  250.  
  251. /**
  252. * 对从频繁项集集合freqItemSet中每迭代出一个频繁项集元素,执行一次关联规则的挖掘
  253. * @param itemSet 频繁项集集合freqItemSet中的一个频繁项集元素
  254. */
  255. public void mine(Set<String> itemSet) {
  256. int n = itemSet.size()/2; // 根据集合的对称性,只需要得到一半的真子集
  257. for(int i=1; i<=n; i++) {
  258. // 得到频繁项集元素itemSet的作为条件的真子集集合
  259. Set<Set<String>> properSubset = ProperSubsetCombination.getProperSubset(i, itemSet);
  260. // 对条件的真子集集合中的每个条件项集,获取到对应的结论项集,从而进一步挖掘频繁关联规则
  261. for(Set<String> conditionSet : properSubset) {
  262. Set<String> conclusionSet = new HashSet<String>();
  263. conclusionSet.addAll(itemSet);
  264. conclusionSet.removeAll(conditionSet); // 删除条件中存在的频繁项
  265. confide(conditionSet, conclusionSet); // 调用计算置信度的方法,并且挖掘出频繁关联规则
  266. }
  267. }
  268. }
  269.  
  270. /**
  271. * 对得到的一个条件项集和对应的结论项集,计算该关联规则的支持计数,从而根据置信度判断是否是频繁关联规则
  272. * @param conditionSet 条件频繁项集
  273. * @param conclusionSet 结论频繁项集
  274. */
  275. public void confide(Set<String> conditionSet, Set<String> conclusionSet) {
  276. // 扫描事务数据库
  277. Iterator<Map.Entry<Integer, Set<String>>> it = txDatabase.entrySet().iterator();
  278. // 统计关联规则支持计数
  279. int conditionToConclusionCnt = 0; // 关联规则(条件项集推出结论项集)计数
  280. int conclusionToConditionCnt = 0; // 关联规则(结论项集推出条件项集)计数
  281. int supCnt = 0; // 关联规则支持计数
  282. while(it.hasNext()) {
  283. Map.Entry<Integer, Set<String>> entry = it.next();
  284. Set<String> txSet = entry.getValue();
  285. Set<String> set1 = new HashSet<String>();
  286. Set<String> set2 = new HashSet<String>();
  287. set1.addAll(conditionSet);
  288.  
  289. set1.removeAll(txSet); // 集合差运算:set-txSet
  290. if(set1.isEmpty()) { // 如果set为空,说明事务数据库中包含条件频繁项conditionSet
  291. // 计数
  292. conditionToConclusionCnt++;
  293. }
  294. set2.addAll(conclusionSet);
  295. set2.removeAll(txSet); // 集合差运算:set-txSet
  296. if(set2.isEmpty()) { // 如果set为空,说明事务数据库中包含结论频繁项conclusionSet
  297. // 计数
  298. conclusionToConditionCnt++;
  299.  
  300. }
  301. if(set1.isEmpty() && set2.isEmpty()) {
  302. supCnt++;
  303. }
  304. }
  305. // 计算置信度
  306. Float conditionToConclusionConf = new Float(supCnt)/new Float(conditionToConclusionCnt);
  307. if(conditionToConclusionConf>=minConf) {
  308. if(assiciationRules.get(conditionSet) == null) { // 如果不存在以该条件频繁项集为条件的关联规则
  309. Set<Set<String>> conclusionSetSet = new HashSet<Set<String>>();
  310. conclusionSetSet.add(conclusionSet);
  311. assiciationRules.put(conditionSet, conclusionSetSet);
  312. }
  313. else {
  314. assiciationRules.get(conditionSet).add(conclusionSet);
  315. }
  316. }
  317. Float conclusionToConditionConf = new Float(supCnt)/new Float(conclusionToConditionCnt);
  318. if(conclusionToConditionConf>=minConf) {
  319. if(assiciationRules.get(conclusionSet) == null) { // 如果不存在以该结论频繁项集为条件的关联规则
  320. Set<Set<String>> conclusionSetSet = new HashSet<Set<String>>();
  321. conclusionSetSet.add(conditionSet);
  322. assiciationRules.put(conclusionSet, conclusionSetSet);
  323. }
  324. else {
  325. assiciationRules.get(conclusionSet).add(conditionSet);
  326. }
  327. }
  328. }
  329. /**
  330. * 经过挖掘得到的频繁项集Map
  331. *
  332. * @return 挖掘得到的频繁项集集合
  333. */
  334. public Map<Integer, Set<Set<String>>> getFreqItemSet() {
  335. return freqItemSet;
  336. }
  337. /**
  338. * 获取挖掘到的全部的频繁关联规则的集合
  339. * @return 频繁关联规则集合
  340. */
  341. public Map<Set<String>, Set<Set<String>>> getAssiciationRules() {
  342. return assiciationRules;
  343. }
  344. }

测试类如下:

  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.Map;
  9. import java.util.Set;
  10. import java.util.TreeSet;
  11.  
  12. import junit.framework.TestCase;
  13. /**
  14. * <B>Apriori算法测试类</B>
  15. *
  16. * @author king
  17. * @date 2013/07/28
  18. */
  19. public class AprioriTest extends TestCase {
  20.  
  21. private Apriori apriori;
  22. private Map<Integer, Set<String>> txDatabase;
  23. private Float minSup = new Float("0.50");
  24. private Float minConf = new Float("0.70");
  25.  
  26. public static void main(String []args) throws Exception {
  27. AprioriTest at = new AprioriTest();
  28. at.setUp();
  29.  
  30. long from = System.currentTimeMillis();
  31. at.testGetFreqItemSet();
  32. long to = System.currentTimeMillis();
  33. System.out.println("耗时:" + (to-from));
  34.  
  35. }
  36.  
  37. @Override
  38. protected void setUp() throws Exception {
  39. // create(); // 构造事务数据库
  40. this.buildData(Integer.MAX_VALUE, "f_faqk_.dat");
  41. apriori = new Apriori(txDatabase, minSup, minConf);
  42. }
  43.  
  44. /**
  45. * 构造模拟事务数据库txDatabase
  46. */
  47. public void create() {
  48. txDatabase = new HashMap<Integer, Set<String>>();
  49. Set<String> set1 = new TreeSet<String>();
  50. set1.add("A");
  51. set1.add("B");
  52. set1.add("C");
  53. set1.add("E");
  54. txDatabase.put(1, set1);
  55. Set<String> set2 = new TreeSet<String>();
  56. set2.add("A");
  57. set2.add("B");
  58. set2.add("C");
  59. txDatabase.put(2, set2);
  60. Set<String> set3 = new TreeSet<String>();
  61. set3.add("C");
  62. set3.add("D");
  63. txDatabase.put(3, set3);
  64. Set<String> set4 = new TreeSet<String>();
  65. set4.add("A");
  66. set4.add("B");
  67. set4.add("E");
  68. txDatabase.put(4, set4);
  69. }
  70.  
  71. /**
  72. * 构造数据集
  73. * @param fileName 存储事务数据的文件名
  74. * @param totalcount 获取的事务数
  75. */
  76. public void buildData(int totalCount, String...fileName) {
  77. txDatabase = new HashMap<Integer, Set<String>>();
  78. if(fileName.length !=0){
  79. File file = new File(fileName[0]);
  80. int count = 0;
  81. try {
  82. BufferedReader reader = new BufferedReader(new FileReader(file));
  83. String line;
  84. while( (line = reader.readLine()) != null){
  85. String []arr = line.split(" ");
  86. Set<String> set = new HashSet<String>();
  87. for(String s : arr)
  88. set.add(s);
  89. count++;
  90. this.txDatabase.put(count, set);
  91.  
  92. if(count >= totalCount) return;
  93. }
  94. } catch (FileNotFoundException e) {
  95. e.printStackTrace();
  96. } catch (IOException e) {
  97. e.printStackTrace();
  98. }
  99. }else{
  100. }
  101. }
  102.  
  103. /**
  104. * 测试挖掘频繁1-项集
  105. */
  106. public void testFreq1ItemSet() {
  107. System.out.println("挖掘频繁1-项集 : " + apriori.getFreq1ItemSet());
  108. }
  109.  
  110. /**
  111. * 测试aprioriGen方法,生成候选频繁项集
  112. */
  113. public void testAprioriGen() {
  114. System.out.println(
  115. "候选频繁2-项集 : " +
  116. this.apriori.aprioriGen(1, this.apriori.getFreq1ItemSet().keySet())
  117. );
  118. }
  119.  
  120. /**
  121. * 测试挖掘频繁2-项集
  122. */
  123. public void testGetFreq2ItemSet() {
  124. System.out.println(
  125. "挖掘频繁2-项集 :" +
  126. this.apriori.getFreqKItemSet(2, this.apriori.getFreq1ItemSet().keySet())
  127. );
  128. }
  129.  
  130. /**
  131. * 测试挖掘频繁3-项集
  132. */
  133. public void testGetFreq3ItemSet() {
  134. System.out.println(
  135. "挖掘频繁3-项集 :" +
  136. this.apriori.getFreqKItemSet(
  137. 3,
  138. this.apriori.getFreqKItemSet(2, this.apriori.getFreq1ItemSet().keySet()).keySet()
  139. )
  140. );
  141. }
  142.  
  143. /**
  144. * 测试挖掘全部频繁项集
  145. */
  146. public void testGetFreqItemSet() {
  147. this.apriori.mineFreqItemSet(); // 挖掘频繁项集
  148. System.out.println("挖掘频繁项集 :" + this.apriori.getFreqItemSet());
  149. }
  150.  
  151. /**
  152. * 测试挖掘全部频繁关联规则
  153. */
  154. public void testMineAssociationRules() {
  155. this.apriori.mineFreqItemSet(); // 挖掘频繁项集
  156. this.apriori.mineAssociationRules();
  157. System.out.println("挖掘频繁关联规则 :" + this.apriori.getAssiciationRules());
  158. }
  159. }

参考:
http://hi.baidu.com/shirdrn/item/5b74a313d55256711009b5d8

在此基础上添加了has_infrequent_subset方法,此方法使用先验知识进行剪枝,是典型Apriori算法必备的。

Apriori算法实现的更多相关文章

  1. Apriori算法的原理与python 实现。

    前言:这是一个老故事, 但每次看总是能从中想到点什么.在一家超市里,有一个有趣的现象:尿布和啤酒赫然摆在一起出售.但是这个奇怪的举措却使尿布和啤酒的销量双双增加了.这不是一个笑话,而是发生在美国沃尔玛 ...

  2. #研发解决方案#基于Apriori算法的Nginx+Lua+ELK异常流量拦截方案

    郑昀 基于杨海波的设计文档 创建于2015/8/13 最后更新于2015/8/25 关键词:异常流量.rate limiting.Nginx.Apriori.频繁项集.先验算法.Lua.ELK 本文档 ...

  3. 数据挖掘算法(四)Apriori算法

    参考文献: 关联分析之Apriori算法

  4. 机器学习实战 - 读书笔记(11) - 使用Apriori算法进行关联分析

    前言 最近在看Peter Harrington写的"机器学习实战",这是我的学习心得,这次是第11章 - 使用Apriori算法进行关联分析. 基本概念 关联分析(associat ...

  5. 关联规则挖掘之apriori算法

    前言: 众所周知,关联规则挖掘是数据挖掘中重要的一部分,如著名的啤酒和尿布的问题.今天要学习的是经典的关联规则挖掘算法--Apriori算法 一.算法的基本原理 由k项频繁集去导出k+1项频繁集. 二 ...

  6. 利用Apriori算法对交通路况的研究

    首先简单描述一下Apriori算法:Apriori算法分为频繁项集的产生和规则的产生. Apriori算法频繁项集的产生: 令ck为候选k-项集的集合,而Fk为频繁k-项集的集合. 1.首先通过单遍扫 ...

  7. Apriori算法例子

    1 Apriori介绍 Apriori算法使用频繁项集的先验知识,使用一种称作逐层搜索的迭代方法,k项集用于探索(k+1)项集.首先,通过扫描事务(交易)记录,找出所有的频繁1项集,该集合记做L1,然 ...

  8. Apriori算法实例----Weka,R, Using Weka in my javacode

    学习数据挖掘工具中,下面使用4种工具来对同一个数据集进行研究. 数据描述:下面这些数据是15个同学选修课程情况,在课程大纲中共有10门课程供学生选择,下面给出具体的选课情况,以ARFF数据文件保存,名 ...

  9. Apriori算法在购物篮分析中的运用

    购物篮分析是一个很经典的数据挖掘案例,运用到了Apriori算法.下面从网上下载的一超市某月份的数据库,利用Apriori算法进行管理分析.例子使用Python+MongoDB 处理过程1 数据建模( ...

  10. 关于apriori算法的一个简单的例子

    apriori算法是关联规则挖掘中很基础也很经典的一个算法,我认为很多教程出现大堆的公式不是很适合一个初学者理解.因此,本文列举一个简单的例子来演示下apriori算法的整个步骤. 下面这个表格是代表 ...

随机推荐

  1. 多线程之Future模式

    详细参见葛一名老师的<Java程序性能优化> Futrue模式:对于多线程,如果线程A要等待线程B的结果,那么线程A没必要等待B,直到B有结果,可以先拿到一个未来的Future,等B有结果 ...

  2. 为什么要用BASE64

    BASE64和其他相似的编码算法通常用于转换二进制数据为文本数据,其目的是为了简化存储或传输.更具体地说,BASE64算法主要用于转换二进 制数据为ASCII字符串格式.Java语言提供了一个非常好的 ...

  3. Flask web开发 处理POST请求(登录案例)

    本文我们以一个登录例子来说明Flask对 post请求的处理机制. 1.创建应用目录,如 mkdir   example cd example 2.在应用目录下创建  run.py文件,内容如下 fr ...

  4. nginx 解决400 bad request 的方法

    nginx的400错误比较难查找原因,因为此错误并不是每次都会出现的,另外,出现错误的时候,通常在浏览器和日志里看不到任何有关提示. 经长时间观察和大量试验查明,此乃request header过大所 ...

  5. 64位CentOS6.2安装erlang及rabbitmqServer

    CentOS 6.2 64bit 安装erlang及RabbitMQ Server 1.操作系统环境(CentOS 6.2 64bit) [root@HAproxy ~]# cat /etc/issu ...

  6. 在mac os 中安装 autoconf and automake

    转载地址:http://www.mattvsworld.com/blog/2010/02/install-the-latest-autoconf-and-automake-on-mac-os-10-6 ...

  7. 基于visual Studio2013解决算法导论之006最大堆排序

     题目 最大堆排序 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #i ...

  8. 区间dp-zoj3541-The Last Puzzle

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3541 题目大意: 在数轴上,有n个按钮,位置递增为d1,d2, ...

  9. 《高质量程序设计指南:C++/C语言》面试题整理

    本试题仅用于考查C++/C程序员的基本编程技能.内容限于C++/C常用 语法,不涉及 数据结构. 算法以及深奥的语法.考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不能反映考生的智力和软 ...

  10. 枚举+搜索 hdu-4431-Mahjong

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4431 题目大意: 给一副牌,求出所有能糊的牌. 解题思路: 枚举每一张牌,看能不能糊. 因为一共只有 ...