由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
BrainTeaser版 - 提问
相关主题
数学题.Depth-first search是否属于动态规划?
推理图的最小生成树问题
出个难题,赌包子问个题: 在1..N中, 所有K个数字组合中的第P个
数独怎么玩呀机器狗用BFS或者DFS把所有棋步都列举出来 (转载)
cheungche 封 hehehehhe 在 Mathematics算法题求助
这个题目能否半小时完成coding?面了,估计没戏
问一道字符串相关的题目。计算器游戏
字典里面如何快速找到一个单词对应的只有一个字母不同的单词贴一道题,帮忙做做code review (How can we generate all possibilities on braces )
相关话题的讨论汇总
话题: xn话题: x1话题: x2话题: so话题: xi
进入BrainTeaser版参与讨论
1 (共1页)
l*******r
发帖数: 322
1
1. 橄榄球比赛中,一方进攻可能得2分,3分,6分,7分,或者8分(当然也可能得0分
)。问比赛中不可能出现什么分数?
2. 推广之:一方进攻可能得分为 0 < x1 < x2 < ... < xn,问比赛中不可能出现什么
分数?
3. 编程:输入一个正整数,如果能被分解成题目2中的分数的组合则输出,否则输出不
能分解。注:不要用穷举。
f*****e
发帖数: 542
2

1分?

【在 l*******r 的大作中提到】
: 1. 橄榄球比赛中,一方进攻可能得2分,3分,6分,7分,或者8分(当然也可能得0分
: )。问比赛中不可能出现什么分数?
: 2. 推广之:一方进攻可能得分为 0 < x1 < x2 < ... < xn,问比赛中不可能出现什么
: 分数?
: 3. 编程:输入一个正整数,如果能被分解成题目2中的分数的组合则输出,否则输出不
: 能分解。注:不要用穷举。

p*****k
发帖数: 318
3
off-topic question. i'm just curious, how to score sole 2pts in football? never saw it in a game. is it same as the one for 8pts?
the first question is pretty simple, only 1 is not possible (6,7 and 8 are redundant anyway).
for the general case, i think the following lemma might help:
two natural numbers p and q. if gcd(p,q)=1, i.e., p and q are coprime, then any integer n>=pq can be expressed as ap+bq, where a and b are nonnegative integers.
so let's say you if x_1 is coprime with some x_i
l*******r
发帖数: 322
4

never saw it in a game. is it same as the one for 8pts?
http://www.mitbbs.com/bbsann2/sports.faq/Football/rulls/football_dummy/footballbasic/%E6%A9%84%E6%A6%84%E7%90%83%E5%85%A5%E9%97%A8
见第一章最后一段,我模糊记得我在电视上看到过一次,当时很不解
are redundant anyway).
这是为了引出下一个问题,所以简单了点
不过我们总可以自己换几个数试试,感性认识一下
then any integer n>=pq can be expressed as ap+bq, where a and b are
nonnegative integers.
possible), you only need to consider scores lower than x_1*x_i.
be achieved. so divide all x_i by y, then it is essentially

【在 p*****k 的大作中提到】
: off-topic question. i'm just curious, how to score sole 2pts in football? never saw it in a game. is it same as the one for 8pts?
: the first question is pretty simple, only 1 is not possible (6,7 and 8 are redundant anyway).
: for the general case, i think the following lemma might help:
: two natural numbers p and q. if gcd(p,q)=1, i.e., p and q are coprime, then any integer n>=pq can be expressed as ap+bq, where a and b are nonnegative integers.
: so let's say you if x_1 is coprime with some x_i

p*****k
发帖数: 318
5
i see, so it is not the 2-point-conversion. thanks.
interestingly if you look up on wikipedia, seems you can get 1pt as well, so-called "conversion safety":
http://en.wikipedia.org/wiki/Safety_(football_score)#Safeties_on_PAT.2Fconversion_tries

【在 l*******r 的大作中提到】
:
: never saw it in a game. is it same as the one for 8pts?
: http://www.mitbbs.com/bbsann2/sports.faq/Football/rulls/football_dummy/footballbasic/%E6%A9%84%E6%A6%84%E7%90%83%E5%85%A5%E9%97%A8
: 见第一章最后一段,我模糊记得我在电视上看到过一次,当时很不解
: are redundant anyway).
: 这是为了引出下一个问题,所以简单了点
: 不过我们总可以自己换几个数试试,感性认识一下
: then any integer n>=pq can be expressed as ap+bq, where a and b are
: nonnegative integers.
: possible), you only need to consider scores lower than x_1*x_i.

l*******r
发帖数: 322
6
接着讨论最后一步,对于小于x1*xi的所有数:
如果只要求对某一个数x进行分解:
1. 构造一棵n岔树,根节点是x,它的子节点从左到右分别是(x-xn)...(x-x2),(x-x1)
,每个子节点又有类似的n个子节点,直到某个节点的数值小于等于0
2. 分解过程是对以上这棵树进行深度优先搜索(DFS),如果达到某个数值为0的节点则
输出路径,否则输出“不可分解”
如果要对一大堆数进行分解,可以考虑以下的预处理:
1. 建立一个长度为x1*xi的数组A[],值初始化为-1
2. A[0] := 0
3. 对x从1到(x1*xi-1)进行以下循环:
3.a. 如果x-xn>=0而且A[x-xn]<>-1,表明(x-xn)可以分解,令A[x]:=xn;结束本次循环
3.b. 否则,测试“x-x(n-1)>=0而且A[x-x(n-1)]<>-1”,如此下去
3.c. 如果所有测试都通不过,则A[x]:=-1,表示它不能被分解
对于任意输入0<=x 正确?高效?

【在 l*******r 的大作中提到】
:
: never saw it in a game. is it same as the one for 8pts?
: http://www.mitbbs.com/bbsann2/sports.faq/Football/rulls/football_dummy/footballbasic/%E6%A9%84%E6%A6%84%E7%90%83%E5%85%A5%E9%97%A8
: 见第一章最后一段,我模糊记得我在电视上看到过一次,当时很不解
: are redundant anyway).
: 这是为了引出下一个问题,所以简单了点
: 不过我们总可以自己换几个数试试,感性认识一下
: then any integer n>=pq can be expressed as ap+bq, where a and b are
: nonnegative integers.
: possible), you only need to consider scores lower than x_1*x_i.

h*******e
发帖数: 225
7
this is a well-known and well-solved problem in combinatorics.
google "Generating Functions". also check out dynamic programming.

【在 l*******r 的大作中提到】
: 接着讨论最后一步,对于小于x1*xi的所有数:
: 如果只要求对某一个数x进行分解:
: 1. 构造一棵n岔树,根节点是x,它的子节点从左到右分别是(x-xn)...(x-x2),(x-x1)
: ,每个子节点又有类似的n个子节点,直到某个节点的数值小于等于0
: 2. 分解过程是对以上这棵树进行深度优先搜索(DFS),如果达到某个数值为0的节点则
: 输出路径,否则输出“不可分解”
: 如果要对一大堆数进行分解,可以考虑以下的预处理:
: 1. 建立一个长度为x1*xi的数组A[],值初始化为-1
: 2. A[0] := 0
: 3. 对x从1到(x1*xi-1)进行以下循环:

p*****k
发帖数: 318
8
hehehehhe, could you elaborate a little bit more, or provide a more specific
link? i kinda know generating function, but not sure how it can be applied
here.
h*******e
发帖数: 225
9
Mathematically, let's formalize the problem by considering each xi as the
value of a kind of coin. Basically you have n kinds of coins with unlimited
supply. So given {xi} and a value m, we want to determine if there exists a
combination of coins s.t. the sum is m.
Define F(t) = [1 + t^x1 + t^(2*x1) + t^(3*x1) + ...] *
[1 + t^x2 + t^(2*x2) + t^(3*x2) + ...] * ...
[1 + t^xn + t^(2*xn) + t^(3*xn) + ...]
The cofficient of the term t^m in F(t)'s expansion is the number of

【在 p*****k 的大作中提到】
: hehehehhe, could you elaborate a little bit more, or provide a more specific
: link? i kinda know generating function, but not sure how it can be applied
: here.

p*****k
发帖数: 318
10
came across Sylvester's result today, very interesting read:
http://en.wikipedia.org/wiki/Sylver_coinage
http://mathworld.wolfram.com/CoinProblem.html
there exists much stronger result than the lemma stated earlier in this thread. hehehehhe, you were right that it is proven by the generating function approach, and is indeed well-known and well-solved.
相关主题
这个题目能否半小时完成coding?Depth-first search是否属于动态规划?
问一道字符串相关的题目。图的最小生成树问题
字典里面如何快速找到一个单词对应的只有一个字母不同的单词问个题: 在1..N中, 所有K个数字组合中的第P个
进入BrainTeaser版参与讨论
l*******r
发帖数: 322
11
哦,发现我原来的两个解法就分别对应动态规划里面的top-down和bottom-up方法
不过我没有想到这就是动态规划
嗯,我的答案都太底层了,接近pseudocode了
应该上来就跟面试官说dynamic programming
没准他手一摆就换下一道题了
嘿嘿

【在 l*******r 的大作中提到】
: 接着讨论最后一步,对于小于x1*xi的所有数:
: 如果只要求对某一个数x进行分解:
: 1. 构造一棵n岔树,根节点是x,它的子节点从左到右分别是(x-xn)...(x-x2),(x-x1)
: ,每个子节点又有类似的n个子节点,直到某个节点的数值小于等于0
: 2. 分解过程是对以上这棵树进行深度优先搜索(DFS),如果达到某个数值为0的节点则
: 输出路径,否则输出“不可分解”
: 如果要对一大堆数进行分解,可以考虑以下的预处理:
: 1. 建立一个长度为x1*xi的数组A[],值初始化为-1
: 2. A[0] := 0
: 3. 对x从1到(x1*xi-1)进行以下循环:

l*******r
发帖数: 322
12
我一般都是边看电视边自己琢磨
字面上的规则都太复杂了
题外话:我发现美式橄榄球的执法非常严格认真,条例也很细致
题外话2:我很不齿“错误判罚也是足球魅力一部分”这类的说法

so-called "conversion safety":

【在 p*****k 的大作中提到】
: i see, so it is not the 2-point-conversion. thanks.
: interestingly if you look up on wikipedia, seems you can get 1pt as well, so-called "conversion safety":
: http://en.wikipedia.org/wiki/Safety_(football_score)#Safeties_on_PAT.2Fconversion_tries

l*******r
发帖数: 322
13
我也没懂
看了那个wiki的链接,但是琢磨不出来到底怎么解决原来的问题的……

need
it
..

【在 p*****k 的大作中提到】
: came across Sylvester's result today, very interesting read:
: http://en.wikipedia.org/wiki/Sylver_coinage
: http://mathworld.wolfram.com/CoinProblem.html
: there exists much stronger result than the lemma stated earlier in this thread. hehehehhe, you were right that it is proven by the generating function approach, and is indeed well-known and well-solved.

w*****y
发帖数: 3900
14
off topic
but do you know in certain senario a team can score 1 pt in football
haha

【在 l*******r 的大作中提到】
: 1. 橄榄球比赛中,一方进攻可能得2分,3分,6分,7分,或者8分(当然也可能得0分
: )。问比赛中不可能出现什么分数?
: 2. 推广之:一方进攻可能得分为 0 < x1 < x2 < ... < xn,问比赛中不可能出现什么
: 分数?
: 3. 编程:输入一个正整数,如果能被分解成题目2中的分数的组合则输出,否则输出不
: 能分解。注:不要用穷举。

b*****g
发帖数: 919
15
用手把球扔进大弹弓?

【在 w*****y 的大作中提到】
: off topic
: but do you know in certain senario a team can score 1 pt in football
: haha

p*****k
发帖数: 318
16
besides the extra point after the touchdown, there is a rare exception to
score one point for a safety:
http://en.wikipedia.org/wiki/Safety_(football_score)#Safeties_on_PAT.2Fconversion_tries
1 (共1页)
进入BrainTeaser版参与讨论
相关主题
贴一道题,帮忙做做code review (How can we generate all possibilities on braces )cheungche 封 hehehehhe 在 Mathematics
问一leetcode题,为什么要resize。题目Generate Parentheses。这个题目能否半小时完成coding?
再出个难点的题问一道字符串相关的题目。
如何证明 lcm(ac,bc)=c*lcm(a,b)字典里面如何快速找到一个单词对应的只有一个字母不同的单词
数学题.Depth-first search是否属于动态规划?
推理图的最小生成树问题
出个难题,赌包子问个题: 在1..N中, 所有K个数字组合中的第P个
数独怎么玩呀机器狗用BFS或者DFS把所有棋步都列举出来 (转载)
相关话题的讨论汇总
话题: xn话题: x1话题: x2话题: so话题: xi