之前是通过hash来做,O(n)。这次为了熟悉通用性的解法,通过双指针来做。时间复杂度为O(nlogn)(即sort的复杂度)。主要是关于sort的用法上不太熟,关于自定义sort规则。C++ Reference中给的示例代码如下: 1 // sort algorithm example 2 #in...
分类:
其他好文 时间:
2014-10-31 11:30:15
阅读次数:
193
题目链接:poj 2408 Anagram Groups
题目大意:给定若干个字符串,将其分组,按照组成元素相同为一组,输出数量最多的前5组,每组按照字典序输出所
有字符串。数量相同的输出字典序较小的一组。
解题思路:将所有的字符串统计字符后hash,排序之后确定每组的个数并且确定一组中字典序最小的字符串。根据个数
以及字符串对组进行排序。
#include
#incl...
分类:
其他好文 时间:
2014-10-30 23:59:45
阅读次数:
448
一个对象只有一个hashcode,多个对象的hashcode可能相同。 源代码位置:java-source/java/lang/String.java,hashCode()方法: public int hashCode() {
int h = hash;
if (h == 0 && value.leng...
分类:
编程语言 时间:
2014-10-30 21:06:57
阅读次数:
180
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, whic...
分类:
其他好文 时间:
2014-10-30 20:42:05
阅读次数:
139
题目很简单,给出n(1 2 #include 3 using namespace std; 4 bool prime[40]; 5 bool hash[40]; 6 int ans[40]; 7 int n; 8 int cas = 1; 9 10 void getprime() {11 ...
分类:
其他好文 时间:
2014-10-30 20:41:33
阅读次数:
229
最近老大说要实现负载均衡,今天试着玩了下。在nginx.conf配置ip_hash;可以让同一IP的请求落到固定的一台服务器,也就可以用session机制了。这里设置前两个是同一个服务器两个端口, weight设置权重,映射的权重。第三个server是第二个服务器的。80端口是用来监听,443、80...
分类:
其他好文 时间:
2014-10-30 19:07:32
阅读次数:
176
//数组去重 Array.prototype.unique5 = function() { var res = [], hash = {}; for(var i=0, elem; (elem = this[i]) != nul...
分类:
编程语言 时间:
2014-10-30 18:31:33
阅读次数:
184
本文转自惜分飞的博客,博客原文地址:www.xifenfei.com/1109.html,支持原创,分享知识! 当一个数据块读入sga区,相应的buffer header会被放置到hash列表上,我们称其这hash chains,chain在中文的意为链条或串的意思,表达就是关连性.如果一个进程想访...
分类:
系统相关 时间:
2014-10-30 14:46:24
阅读次数:
218
StoredProcedure是一个抽象类,必须写一个子类来继承它,这个类是用来简化JDBCTemplate运行存储过程操作的。首先我们写一个实现类:package com.huaye.framework.dao;import java.sql.Types;import java.util.Hash...
分类:
编程语言 时间:
2014-10-30 14:44:51
阅读次数:
168
#manshellbuiltinsBASH_BUILTINS(1)BASH_BUILTINS(1)NAMEbash,:,.,[,alias,bg,bind,break,builtin,cd,command,comp-gen,complete,continue,declare,dirs,disown,echo,enable,eval,exec,exit,export,fc,fg,getopts,hash,help,history,jobs,kill,let,local,logout,popd,printf,pu..
分类:
系统相关 时间:
2014-10-30 01:55:08
阅读次数:
222