由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 3sum problem
相关主题
Check if the sum of two integers in an integer array eqauls to the given number 一个哈希表问题
求助一个std::map的怪问题面试题 -算法?
what kind of reason might cause this problem? 两道M软件大公司的最新面世算法题 (转载)
请教高手一个C++问题help on GAMS! thx!!
关于process and threads的问题HTML print an image
hashtable question谁能说说Perl, Python, Tcl各自的优缺点?主要应用场合?
贡献一下:本版上搜集的 Google 面试题 (转载)Interview questions about hash function
INTEGER搜索求建议[合集] &x[1]和x+1是一回事吧?不管c还是c++?
相关话题的讨论汇总
话题: 3sum话题: problem话题: tuples话题: hash
进入Programming版参与讨论
1 (共1页)
a*****t
发帖数: 30
1
The 3sum problem is defined as follows:
given a set S of n integers, dothere exist three elements {a, b, c} 2 S such
that a + b + c = 0?
This is a linear satisfiability problem. 3sum can be solved using a simple
algorithm with O(n^2) runtime (sort S, then test 3-tuples intelligently).
我不是特别清楚如何 "test 3-tuples intelligently" in O(n^2).
能给点意见吗? 多谢
g*****g
发帖数: 34805
2
I can think of a simple one.
hash the opposite of every number.
Now add every pair (C(N, 2)= O(N^2)) and check hash O(1)

such

【在 a*****t 的大作中提到】
: The 3sum problem is defined as follows:
: given a set S of n integers, dothere exist three elements {a, b, c} 2 S such
: that a + b + c = 0?
: This is a linear satisfiability problem. 3sum can be solved using a simple
: algorithm with O(n^2) runtime (sort S, then test 3-tuples intelligently).
: 我不是特别清楚如何 "test 3-tuples intelligently" in O(n^2).
: 能给点意见吗? 多谢

X****r
发帖数: 3557
3
No need to hash to find pairs of (a,b) from sets A and B respectively such
that
a + b == s in O(N+M) time, where the size of A is N and size of B is M, if
both
A and B are sorted and contain unique members. Just start from (i,j) = (1,m)
,
and increase i if a_i + b_j < s or decrease j if a_i + b_j > s.

【在 g*****g 的大作中提到】
: I can think of a simple one.
: hash the opposite of every number.
: Now add every pair (C(N, 2)= O(N^2)) and check hash O(1)
:
: such

a*****t
发帖数: 30
4
Hash 方法不错。
感觉 Xentar 更简洁,漂亮些。
多谢!!
c**a
发帖数: 316
5
Three sum?
funny title.

such

【在 a*****t 的大作中提到】
: The 3sum problem is defined as follows:
: given a set S of n integers, dothere exist three elements {a, b, c} 2 S such
: that a + b + c = 0?
: This is a linear satisfiability problem. 3sum can be solved using a simple
: algorithm with O(n^2) runtime (sort S, then test 3-tuples intelligently).
: 我不是特别清楚如何 "test 3-tuples intelligently" in O(n^2).
: 能给点意见吗? 多谢

1 (共1页)
进入Programming版参与讨论
相关主题
[合集] &x[1]和x+1是一回事吧?不管c还是c++?关于process and threads的问题
一道c++的考古题hashtable question
GNUPLOT怎么样画大小不同的点贡献一下:本版上搜集的 Google 面试题 (转载)
花了一个小时学习了pythonINTEGER搜索求建议
Check if the sum of two integers in an integer array eqauls to the given number 一个哈希表问题
求助一个std::map的怪问题面试题 -算法?
what kind of reason might cause this problem? 两道M软件大公司的最新面世算法题 (转载)
请教高手一个C++问题help on GAMS! thx!!
相关话题的讨论汇总
话题: 3sum话题: problem话题: tuples话题: hash