免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: hll
打印 上一主题 下一主题

[算法] 今天面试栽在这个小题上了 [复制链接]

论坛徽章:
0
121 [报告]
发表于 2008-03-13 01:51 |只看该作者
不用争了    这题没有答案,只是一个考察解决问题的能力和思路的题目

就算你排出来球的重量顺序  1 2 3...89 10      假设重量为1  2  ...8  9  10    那么重量差最小的排法是什么呢  是1  3  5  7  9-2 4 6 8 10么?

显然不是把??


重量差最小的排法是什么呢 ?  没有规律把?更别说不知道重量大小的球了  不是么?

论坛徽章:
0
122 [报告]
发表于 2008-03-13 04:10 |只看该作者

Crazy Questions at Google Job Interview(zt)

Crazy Questions at Google Job Interview

A friend of mine had an interview a couple weeks ago with Google Inc. He provided me a list of just some of the questions he was asked. I’ve added a few more from others I have talked to who had interviews with the internet giant, Google, as well. See if you can answer them. Many are open ended with several right answers, therefore I did not provide the answers.

1. How many golf balls can fit in a school bus?

2. You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do?

3. How much should you charge to wash all the windows in Seattle?

4. How would you find out if a machine’s stack grows up or down in memory?

5. Explain a database in three sentences to your eight-year-old nephew.

6. How many times a day does a clock’s hands overlap?

7. You have to get from point A to point B. You don’t know if you can get there. What would you do?

8. Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?

9. Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announces that at least one husband has been unfaithful. What happens?

10. In a country in which people only want boys, every family continues to have children until they have a boy. if they have a girl, they have another child. if they have a boy, they stop. what is the proportion of boys to girls in the country?

11. If the probability of observing a car in 30 minutes on a highway is 0.95, what is the probability of observing a car in 10 minutes (assuming constant default probability)?

12. If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands? (The answer to this is not zero!)

13. Four people need to cross a rickety rope bridge to get back to their camp at night. Unfortunately, they only have one flashlight and it only has enough light left for seventeen minutes. The bridge is too dangerous to cross without a flashlight, and it
hll 该用户已被删除
123 [报告]
发表于 2008-03-13 09:54 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
124 [报告]
发表于 2008-03-13 14:58 |只看该作者
晕死,我只是提个方法,难道你们就不会从我这方法里深入下去?

不管最重或最轻,总会有结果

有结果的那一边,不管是比1重或轻,想再平衡,那两边再拿出一个作为参照,继续比下去,用不了几下就出来了

论坛徽章:
0
125 [报告]
发表于 2008-03-13 15:26 |只看该作者
原帖由 sitxw 于 2008-3-10 15:42 发表
我觉得答案应该是这样的:
把所有小球放在手里(如果可以用篮子更好)不停的晃一会,根据物理原理重的小球应该会在下面,轻的应该在上面。这样再依次的放在天平两侧。
(没有看所有的回帖,不知道前面有没有人 ...



















。。。。。。。。。。。

论坛徽章:
0
126 [报告]
发表于 2008-03-13 20:29 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
127 [报告]
发表于 2008-03-16 00:34 |只看该作者
考。帖多懒得看。我认为:
任意取一个球做砝码开始称,把所以比“砝码”重的放A堆,相等的放B堆,轻的放C堆。称完一轮后把“砝码”放在B堆。
很明显此时分别从A、B、C任取a、b、c球都有a>b>c。
接着各个击破,分别对A、B、C堆采取同样的办法称量。。。
直到10个球按从重量排序好了。这应该很快。。。
----
然后。。。

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:56:11
128 [报告]
发表于 2008-03-16 06:29 |只看该作者
本栏目下如下标题讨论的是相同的问题:       
有10个小球质量未知,一个天平没有刻度,要求一边放5个使两边质量之差最小

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:56:11
129 [报告]
发表于 2008-03-17 14:34 |只看该作者
把球任意进行编号,并且分两堆,各5个。
可以记住这两堆的成员号码。用天平称量。如果相同,结束。
如果不同,重的堆为上限,轻的堆为下限。

列出10中取5的组合全部可能,这可在网上找到源代码。
依次从组合可能中取出一个可能,
如果该可能的质量在上下限之间,
则把该可能与剩下的五个作为新的上下限。
如果新的上下限相同,结束。
如果该可能的质量不在上下限之间,就取组合中的下一个可能。
组合中所有可能都试完时。上下限就是结果。

如何测定质量在上下限之间?
记住的上下限成员之一与取出的“可能”进行称量。
有个小技巧,即要把要比较的两个成员中相同编号的小球排除,
这样才能保证有足够的球来代表两个要比较的成员。

下面就是C源代码,编译后即可执行,执行语法命令后跟空白隔开的10个数字。
./a.out 100 99 1 5 42 42 42 5 42 42


#include <stdio.h>
#include <stdlib.h>
#define q 176

int j[]={
0,1,2,3,4, 5,6,7,8,9, 0,1,2,3,5, 4,6,7,8,9, 0,1,2,4,5, 3,6,7,8,9, 0,1,3,4,5, 2,6,7,8,9,
0,2,3,4,5, 1,6,7,8,9, 1,2,3,4,5, 0,6,7,8,9, 0,1,2,3,6, 4,5,7,8,9, 0,1,2,4,6, 3,5,7,8,9,
0,1,3,4,6, 2,5,7,8,9, 0,2,3,4,6, 1,5,7,8,9, 1,2,3,4,6, 0,5,7,8,9, 0,1,2,5,6, 3,4,7,8,9,
0,1,3,5,6, 2,4,7,8,9, 0,2,3,5,6, 1,4,7,8,9, 1,2,3,5,6, 0,4,7,8,9, 0,1,4,5,6, 2,3,7,8,9,
0,2,4,5,6, 1,3,7,8,9, 1,2,4,5,6, 0,3,7,8,9, 0,3,4,5,6, 1,2,7,8,9, 1,3,4,5,6, 0,2,7,8,9,
2,3,4,5,6, 0,1,7,8,9, 0,1,2,3,7, 4,5,6,8,9, 0,1,2,4,7, 3,5,6,8,9, 0,1,3,4,7, 2,5,6,8,9,
0,2,3,4,7, 1,5,6,8,9, 1,2,3,4,7, 0,5,6,8,9, 0,1,2,5,7, 3,4,6,8,9, 0,1,3,5,7, 2,4,6,8,9,
0,2,3,5,7, 1,4,6,8,9, 1,2,3,5,7, 0,4,6,8,9, 0,1,4,5,7, 2,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,7,9, 0,1,5,6,8, 0,1,5,7,9, 2,3,4,6,8,
0,2,5,7,9, 1,3,4,6,8, 1,2,5,7,9, 0,3,4,6,8, 0,3,5,7,9, 1,2,4,6,8, 1,3,5,7,9, 0,2,4,6,8
};

int i[10];



h(int *m, int *n)
{        int a;

        *m = 0;
        for(a=0; a < 5; a++)  *m += i[n[a]];
}



p()
{        int a, d;
        int c, f[5];
        int b, e[5];
        int g, k[5];

        for(a=0; a < 5; a++)
        {        f[a] = 2*a;
                e[a] = 2*a+1;
        }
        h((int *)&c, (int *)&f);
        h((int *)&b, (int *)&e);
        if(c != b)
        {        for(d=0; d < q; d++)
                {
                        for(a=0; a < 5; a++)  k[a] = *(j+d*10+a);
                        h((int *)&g, (int *)&k);
                        if(((g > b) && (g < c)) || ((g < b) && (g > c)))
                        {
                                for(a=0; a < 5; a++)
                                {        f[a] = *(j+d*10+a);
                                        e[a] = *(j+d*10+a+5);
                                }
                                h((int *)&c, (int *)&f);
                                h((int *)&b, (int *)&e);
                                if(c == b)  break;
                        }
                }
        }
        printf("%d         ", b);
        for(a=0; a < 5; a++) printf("%d ", i[e[a]]); printf("\n");
        printf("%d        ", c);
        for(a=0; a < 5; a++) printf("%d ", i[f[a]]); printf("\n");
        printf("相差 %d\n", (b > c)? b-c : c-b);
}



int main(int o, char *l[])
{        int a, d;

        if(o < 10)
        {        printf("Usage : %s 100 99 42 42 42 42 42 5 5 1\n", l[0]);
                  exit(0);
        }
        for(a=0; a < 10; a++)
        {        sscanf(l[a+1], "%d", &d);
                i[a] = d;
        }
        p();
}

论坛徽章:
0
130 [报告]
发表于 2008-03-17 15:16 |只看该作者
我想是这样的,首先将10个球排序。比如 80 50 37 12 10 6 5 5 3 1
将最重的两个球分别放在两个盘中
                                  80                     50
再把第三个球放在轻的盘中
                                                          37
再把下一个球放在轻的盘中
                                    12
再把下一个球放在轻的盘中                           10
                                                   
再把下一个球放在轻的盘中       6

再把下一个球放在轻的盘中                           5

再把下一个球放在轻的盘中       5

再把下一个球放在轻的盘中                           3

再把下一个球放在轻的盘中       1

                         total:    104                      105  

如果是标准的10 9 8 7 6 5 4 3 2 1

步骤是                          10                          9
                                                               8
                                  7
                                                               6
                                  5                        
                                  4
                                                                3
                                  2
                                                                1

                        total: 28                        27

[ 本帖最后由 LOSO 于 2008-3-17 15:25 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP