由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Quant版 - 两道算法题 (转载)
相关主题
[合集] another interview question要面一个algorithm trader的职位
how to compute implied volatility from option price in BS world?问一下algorithm的书
A INTERVIEW PROBLEM问三个编程面试题
an interview question(finance)coding
一个问题求推荐C++和programming/算法面试书籍
an interview algorithm question about finding even occuring (转载)想做编程方面的金融工作 PhD level的,如何准备
[合集] C++ 里面 long 怎么 进行 bitwise ANDbrainteaser两道老题
[合集] Which math/stat language is most popular on the street?[合集] brainteaser两道老题
相关话题的讨论汇总
话题: int话题: min话题: max话题: method话题: algorithm
进入Quant版参与讨论
1 (共1页)
w*****e
发帖数: 158
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: woommle (mm), 信区: JobHunting
标 题: 两道算法题
发信站: BBS 未名空间站 (Mon Sep 27 16:56:25 2010, 美东)
1) given the whole range of 6 digit numbers, design an algorithm which
prints out numbers which have the sum of the right 3 digits equal the left
3 digits? like 123600, 345435 etc.
2)design an algorithm to find square_root of a float? how do you make the
algorithm efficient?
第一题:除了每个数检验之外,还有什么更快得方法吗?
第二题:貌似可以用bisection method 或者 Newton method, Newton method 收敛的
更快
一些。有什么地方需要注意或者
k*******d
发帖数: 1340
2
第一个问题是从100000-999999中吗?那么应该不需要每个查过去,前三位从100-999穷
举,对每一个前三位,给定了数字和,穷举出所有可能的后三位,前后拼起来就可以了。
具体做起来我想可以这样,
for i = 1 - 999
array[i] = 三位数字的和。
建立一个数组,size 27,每个元素是一个链表,每个链表里面的三位数数字和是一样的
for i = 0 - 999
linkedlist[array[i]].append(i).
for i = 100 to 999
for j in linkedlist[array[i]]
i 和 j 拼起来就是想要的
时间空间都是O(1000),可能空间用大了一些
z****g
发帖数: 1978
3
1) Dynamic programming
2) You are right about traditional method. But for a really fast and dirty
way, check the math class for Quake, which uses a 'Misery' constant to
bitwise shift the original value.
z****g
发帖数: 1978
4
Sorry, 1) is wrong, I thought you are given 6 digits and asked to figure
out all the valid numbers.

dirty

【在 z****g 的大作中提到】
: 1) Dynamic programming
: 2) You are right about traditional method. But for a really fast and dirty
: way, check the math class for Quake, which uses a 'Misery' constant to
: bitwise shift the original value.

b********u
发帖数: 63
5
1)
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)>(y)?(x):(y))
for (int a = 1; a <= 9; ++a)
{
for (int b = 0; b <= 9; ++b)
{
for (int c = 0; c <= 9; ++c)
{
for (int d = MAX(a+b+c-18,0); d <= MIN(9, a+b+c); ++d)
{
for (int e = MAX(a+b+c-d-9,0); e <= MIN(9, a+b+c-d); ++e)
{
int f = a+b+c-d-e;
assert(f >= 0 && f <= 9);
cout << a << b << c << d << e << f << endl;
}
}
}
}
}

【在 w*****e 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: woommle (mm), 信区: JobHunting
: 标 题: 两道算法题
: 发信站: BBS 未名空间站 (Mon Sep 27 16:56:25 2010, 美东)
: 1) given the whole range of 6 digit numbers, design an algorithm which
: prints out numbers which have the sum of the right 3 digits equal the left
: 3 digits? like 123600, 345435 etc.
: 2)design an algorithm to find square_root of a float? how do you make the
: algorithm efficient?
: 第一题:除了每个数检验之外,还有什么更快得方法吗?

w*****e
发帖数: 158
6
Nice, this is very nice idea. Thank you.
Like the hashtable with chaining.

了。
样的

【在 k*******d 的大作中提到】
: 第一个问题是从100000-999999中吗?那么应该不需要每个查过去,前三位从100-999穷
: 举,对每一个前三位,给定了数字和,穷举出所有可能的后三位,前后拼起来就可以了。
: 具体做起来我想可以这样,
: for i = 1 - 999
: array[i] = 三位数字的和。
: 建立一个数组,size 27,每个元素是一个链表,每个链表里面的三位数数字和是一样的
: for i = 0 - 999
: linkedlist[array[i]].append(i).
: for i = 100 to 999
: for j in linkedlist[array[i]]

1 (共1页)
进入Quant版参与讨论
相关主题
[合集] brainteaser两道老题一个问题
[合集] 说两道题(probability & options)an interview algorithm question about finding even occuring (转载)
两道题(brainteaser)[合集] C++ 里面 long 怎么 进行 bitwise AND
问两道probability的题[合集] Which math/stat language is most popular on the street?
[合集] another interview question要面一个algorithm trader的职位
how to compute implied volatility from option price in BS world?问一下algorithm的书
A INTERVIEW PROBLEM问三个编程面试题
an interview question(finance)coding
相关话题的讨论汇总
话题: int话题: min话题: max话题: method话题: algorithm