由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求助:2倍年龄问题的通项解析式问题
相关主题
二爷,你信箱满了诡异的number of islands.
一道program challenge的题再提两个问题
问一道题一道老题
Divide Two Integersstable rearrange an integer array with + and -
再问一道题Help, Algorithms questions
求教一道DP的面试题,minimum adjustment cost问一道题(1)
question about big data问几道算法题
求教一下,我的这个代码有什么问题leecode上的divide two integers问题
相关话题的讨论汇总
话题: length话题: case话题: otherwise话题: integer话题: divides
进入JobHunting版参与讨论
1 (共1页)
M*****y
发帖数: 666
1
如果两个人的年龄差是 d = m + x ( m a non- negative integer, x in [0,1) ),
determine the length of time during which the older one is k times the age
of the younger one, where k is an integer bigger than 1.
let k = p/q be a rational number, k > 1. Answer in terms of k, d, m and or x.
请会解的高手给一些指导,bow//
B*****t
发帖数: 335
2
设过了p年后一个人的年龄正好是另一个人年龄的k倍. 就是接下面的方程
k[a+p]=[a+m+x+p]; set a+p=P, [x] is floor of x;
==> k[P] = [P+m+x],
简单的思路如下,不明白的话,建议自己画个阶梯函数的图,一目了然。
f1(P)=k[P]和f2(P)=[P+d]都是单调递增的阶梯函数。
f1(P)<=f2(P) 当P->0
f1(P)>f2(P) 当P->oo,
故f1和f2一定有交差, 但是当k>2时不一定有交点!!!!
接着注意到f1的取值为..q-k, q, q+k, q+2k,q为整数。可以看到每当P增加1时,f1的
值增加k,
同理每当P+d增加1时,f2的值每次提升1。所以随着P的增加一旦f1超过f2,就再也追不
上了。
严格来说,设f1(P)=f2(P)=z,题目的本质就是解个不等式方程,z和k是整数,P和d是
实数
z/k<=P z<=P+d 讨论一下答案就出来了。

x.

【在 M*****y 的大作中提到】
: 如果两个人的年龄差是 d = m + x ( m a non- negative integer, x in [0,1) ),
: determine the length of time during which the older one is k times the age
: of the younger one, where k is an integer bigger than 1.
: let k = p/q be a rational number, k > 1. Answer in terms of k, d, m and or x.
: 请会解的高手给一些指导,bow//

M*****y
发帖数: 666
3
Figure out the solution:
K * [t] = [t+m+x]
d = m+x
case 1: t >= m/ (k-1) && m = (K-1)*[t] && t case 2: t>=m/(k-1) + 1-x&& m+1=(k-1)*[t]&&t For case 1: if (K-1) divides m is true , then length is 1-x, Otherwise,
length is 0
For case 2: if (k-1) divides (m+1) is true, then length is x, Otherwise,
length is 0
The final result should be the sum of length in case 1 and case 2

x.

【在 M*****y 的大作中提到】
: 如果两个人的年龄差是 d = m + x ( m a non- negative integer, x in [0,1) ),
: determine the length of time during which the older one is k times the age
: of the younger one, where k is an integer bigger than 1.
: let k = p/q be a rational number, k > 1. Answer in terms of k, d, m and or x.
: 请会解的高手给一些指导,bow//

1 (共1页)
进入JobHunting版参与讨论
相关主题
leecode上的divide two integers问题再问一道题
Leetcode Divide two integers 的题求教一道DP的面试题,minimum adjustment cost
讨论一道面试题question about big data
Divide Two Integers求教一下,我的这个代码有什么问题
二爷,你信箱满了诡异的number of islands.
一道program challenge的题再提两个问题
问一道题一道老题
Divide Two Integersstable rearrange an integer array with + and -
相关话题的讨论汇总
话题: length话题: case话题: otherwise话题: integer话题: divides