Baidu Ball(y) = x

JohnsonElizeee 2010-10-27 12:17:21
Baidu:
用天平(只能比较,不能称重)从一堆小球中找出其中唯一一个较轻的,
使用x次天平 最多可以从y个小球中找出较轻的那个,求y与x的关系式。

set Ball(y) = x, we could get the following relation:
Ball(1) = 0;
Ball(2) = 1;
Ball(3) = 1;
Ball(4) = 2;
Ball(5) = 2;
Ball(6) = 2;
Ball(7) = 2;
Ball(8) = 2;
Ball(9) = 2;
Ball(10) = 3;
....
Ball(14) = 3;

set j is the second-max factor of y, as for number 28,
all the factors are 1, 2, 4, 7, 14, 28. so, j = 14.
set i is times number for i*j = y,
I get a relation between y and x: Ball(y) = (i/2) + Ball(j);

if y is a prime number, as 17, and its factors are 1 and itself, 17.
Ball(y) = Ball(y-1);

conclusion:

set j is the second-max factor of y and i*j = y;
if(j == 1) j = y-1; /* y is a prime number */
Ball(y) = (i/2) + Ball(j)

This opinion is out of full validation and test.
is it right?
...全文
147 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zbo 2010-10-27
  • 打赏
  • 举报
回复
Ball(23)=Ball(22),
Ball(22)=(2/2)+ball(11).
Ball(11)=3,

Ball(22)=3->

if ([1,2,3,4,5,6,7]>[8,9,10,11,12,13,14])
{ if ([1,2]>[3、4]) then [3]vs[4]->find out.
else if [1,2]==[3,4] then [5]vs[6] find out
}
else if ([1,2,3,4,5,6,7]==[8,9,10,11,12,13,14])
{ if [15、16、17]>[18、19、20] then [18]vs[19],find out
else if [15、16、17]=[18、19、20],then [21]vs[22] find out}
}


zbo 2010-10-27
  • 打赏
  • 举报
回复
5楼说的很有道理,值得我学习。
我只是举了个反例,没有考虑过真正的结论应该是什么。
还有,昨天看了另一篇帖子才知道楼主也是中国人,我还以为是老外,回帖时一个中文没敢打。
michael122 2010-10-27
  • 打赏
  • 举报
回复
不就是3^n的关系么
JohnsonElizeee 2010-10-27
  • 打赏
  • 举报
回复

#include <stdio.h>

int Ball(int y)
{
if(y <= 3) return 1;
return 1+Ball( y/3 * 3 == y ? y/3 : y/3 +1 );
}

int F(int x)
{
//assert(x > 0);
int y = 2;
while(1) if(Ball(y++) > x) break;
return y-2;
}

int main()
{
int i = 0;
for(i = 1; i < 16; i++) {
printf("F(%2d)=%9d \t", i, F(i));
if(i%3 == 0) puts("");
}
puts("");
return getchar();
}


JohnsonElizeee 2010-10-27
  • 打赏
  • 举报
回复

1 #include <stdio.h>
2 #include <math.h>
3
4 int Ball(int y)
5 {
6 if(y <= 3) return 1;
7 return 1+Ball( y/3 * 3 == y ? y/3 : y/3 +1 );
8 }
9 int main()
10 {
11 int i = 0;
12 for(i = 2; i < 200; i++) {
13 printf("Ball(%3d)=%d \t", i, Ball(i));
14 if(i%5 == 0) puts("");
15 }
16 puts("");
17 return 0;
18 }

JohnsonElizeee 2010-10-27
  • 打赏
  • 举报
回复
Yeah, this is a wrong deduce.
set j is the second-max factor of y and i*j = y;
if(j == 1) j = y-1; /* y is a prime number */
Ball(y) = (i/2) + Ball(j)

in fact, this one may be better.


set j is the second-max factor of y and i*j = y;
if(j == 1) j = y-1; /* y is a prime number */
Ball(y) = (i/2) + Ball(j)



Ball( 2)=1 Ball( 3)=1 Ball( 4)=2 Ball( 5)=2
Ball( 6)=2 Ball( 7)=2 Ball( 8)=2 Ball( 9)=2 Ball( 10)=3
Ball( 11)=3 Ball( 12)=3 Ball( 13)=3 Ball( 14)=3 Ball( 15)=3
Ball( 16)=3 Ball( 17)=3 Ball( 18)=3 Ball( 19)=3 Ball( 20)=3
Ball( 21)=3 Ball( 22)=3 Ball( 23)=3 Ball( 24)=3 Ball( 25)=3
Ball( 26)=3 Ball( 27)=3 Ball( 28)=4 Ball( 29)=4 Ball( 30)=4
Ball( 31)=4 Ball( 32)=4 Ball( 33)=4 Ball( 34)=4 Ball( 35)=4
Ball( 36)=4 Ball( 37)=4 Ball( 38)=4 Ball( 39)=4 Ball( 40)=4
Ball( 41)=4 Ball( 42)=4 Ball( 43)=4 Ball( 44)=4 Ball( 45)=4
Ball( 46)=4 Ball( 47)=4 Ball( 48)=4 Ball( 49)=4 Ball( 50)=4
Ball( 51)=4 Ball( 52)=4 Ball( 53)=4 Ball( 54)=4 Ball( 55)=4
Ball( 56)=4 Ball( 57)=4 Ball( 58)=4 Ball( 59)=4 Ball( 60)=4
Ball( 61)=4 Ball( 62)=4 Ball( 63)=4 Ball( 64)=4 Ball( 65)=4
Ball( 66)=4 Ball( 67)=4 Ball( 68)=4 Ball( 69)=4 Ball( 70)=4
Ball( 71)=4 Ball( 72)=4 Ball( 73)=4 Ball( 74)=4 Ball( 75)=4
Ball( 76)=4 Ball( 77)=4 Ball( 78)=4 Ball( 79)=4 Ball( 80)=4
Ball( 81)=4 Ball( 82)=5 Ball( 83)=5 Ball( 84)=5 Ball( 85)=5
Ball( 86)=5 Ball( 87)=5 Ball( 88)=5 Ball( 89)=5 Ball( 90)=5
Ball( 91)=5 Ball( 92)=5 Ball( 93)=5 Ball( 94)=5 Ball( 95)=5
Ball( 96)=5 Ball( 97)=5 Ball( 98)=5 Ball( 99)=5 Ball(100)=5
Ball(101)=5 Ball(102)=5 Ball(103)=5 Ball(104)=5 Ball(105)=5
Ball(106)=5 Ball(107)=5 Ball(108)=5 Ball(109)=5 Ball(110)=5
Ball(111)=5 Ball(112)=5 Ball(113)=5 Ball(114)=5 Ball(115)=5
Ball(116)=5 Ball(117)=5 Ball(118)=5 Ball(119)=5 Ball(120)=5
Ball(121)=5 Ball(122)=5 Ball(123)=5 Ball(124)=5 Ball(125)=5
Ball(126)=5 Ball(127)=5 Ball(128)=5 Ball(129)=5 Ball(130)=5
Ball(131)=5 Ball(132)=5 Ball(133)=5 Ball(134)=5 Ball(135)=5
Ball(136)=5 Ball(137)=5 Ball(138)=5 Ball(139)=5 Ball(140)=5
Ball(141)=5 Ball(142)=5 Ball(143)=5 Ball(144)=5 Ball(145)=5
Ball(146)=5 Ball(147)=5 Ball(148)=5 Ball(149)=5 Ball(150)=5
Ball(151)=5 Ball(152)=5 Ball(153)=5 Ball(154)=5 Ball(155)=5
Ball(156)=5 Ball(157)=5 Ball(158)=5 Ball(159)=5 Ball(160)=5
Ball(161)=5 Ball(162)=5 Ball(163)=5 Ball(164)=5 Ball(165)=5
Ball(166)=5 Ball(167)=5 Ball(168)=5 Ball(169)=5 Ball(170)=5
Ball(171)=5 Ball(172)=5 Ball(173)=5 Ball(174)=5 Ball(175)=5
Ball(176)=5 Ball(177)=5 Ball(178)=5 Ball(179)=5 Ball(180)=5
Ball(181)=5 Ball(182)=5 Ball(183)=5 Ball(184)=5 Ball(185)=5
Ball(186)=5 Ball(187)=5 Ball(188)=5 Ball(189)=5 Ball(190)=5
Ball(191)=5 Ball(192)=5 Ball(193)=5 Ball(194)=5 Ball(195)=5
Ball(196)=5 Ball(197)=5 Ball(198)=5 Ball(199)=5

33,009

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧