您的位置:首页 > 职场人生

【笔试or面试】美团2014校园招聘

2013-09-26 02:47 411 查看
声明:题目来自网上,此处只做知识的积累和讨论,不建议转载和传播。

题目:/article/1385381.html

笔试题:

1.给出一堆硬币,不断重复一个操作:若是正面,则随意一抛;若是反面,则翻过来,问最后这堆硬币的正反比例稳不稳定,稳定的话是多少?

答:假设最后能够稳定,则可以得到以下的式子:x/y=(x/2+y)/(x/2),求得x/y=2。

2.概率题。给出甲乙两个生产车间占全厂的比例:P(A)和P(B),再给出各自的产品不合格率:P(C|A)和P(C|B),求不合格产品是甲厂生产的概率P(A|C)?

答:由条件概率公式可得,P(C|A)=P(AC)/P(A),P(C|B)=P(BC)/P(B);再由全概率公式得,P(C)=P(AC)+P(BC);最后求得P(A|C)=P(AC)/P(C)=P(C|A)×P(A)/P(C)。

3.给出50盏灯,从1到50编号,初始所有灯处于全灭状态;然后进行50轮按键,第x轮将编号为x的倍数的灯都按一次,按一次转换一次状态,问最后有多少盏灯亮着?

答:对于每个编号n,求m轮中有多少轮号是n的约数,有多少个按多少次,一般除了平方数都是约数是成对出现的,所以这道题就是在n=m的情况下是求n以内的平方数有多少个。

4.有一个access()函数,现在写一个safe_access()函数,如果调用次数>R/sec就返回错误,否则调用access(),返回success。

答:VS环境下运行正确,Linux下要重新实现clock()函数。http://bbs.csdn.net/topics/100188430

#include <time.h>
#include <iostream>

using namespace std;

bool counter()
{
static clock_t last_time = 0;
static double min_interval =  CLOCKS_PER_SEC / 100.0;
clock_t current_time = clock();

cout << current_time << endl;
if( current_time - last_time < min_interval )
{
cout << CLOCKS_PER_SEC << endl;
cout << "interval_now: " << current_time - last_time << endl;
return false;
}
else{
last_time = current_time;
}

return true;
}

int main()
{
//while( true )
{
if( !counter() )
{
cout << "fail" << endl;
}
else{
cout << "success" << endl;
//system("pause");
}
}

return 0;
}


5.交换链表,给一个整数k,将链表的每k个节点转置,不满k个不做操作。

答:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <malloc.h>
using namespace std;

struct node{
int num;
node* next;
};
typedef node* List;

bool isHeadChange = false;

node* reverseK(List pre, List end, int k)
{
List begin = pre->next;
List kNext = end->next;
List pTemp = begin;
List cur = begin->next;
List nTemp = cur->next;
while(k--){
cur->next = pTemp;
pTemp = cur;
if(nTemp){
cur = nTemp;
nTemp = nTemp->next;
}
}
pre->next = cur;
begin->next = kNext;
return begin;
}

node* kReverse(List head, int k)
{
if(k == 1)	return head;

// don't know the length of list, so travel the list
List tNode = head;
int count = 1;

// new a node to represent the pre node
List pre = new node;
pre->next = head;

while(tNode){
// reach the 3th node
if(count == 3){
// do k - 1 reverses
pre = reverseK(pre, tNode, k-1);
if(!isHeadChange){
head = tNode;
isHeadChange = true;
}
tNode = pre;
count = 0;
}
tNode = tNode->next;
count++;
}
return head;
}

void print(List head)
{
List temp = head;
while(temp != NULL){
cout << temp->num << " ";
temp = temp->next;
}
cout << endl;
}

int main()
{
List head = new node, cur = head;
head->num = 1;	head->next = NULL;
for(int i = 2; i <= 6; i++){
cur->next = new node;
cur = cur->next;
cur->num = i;
cur->next = NULL;
}
// test
print(head);
head = kReverse(head, 3);
print(head);
return 0;
}

比较两个相同类型的指针是否相等。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <malloc.h>
using namespace std;

struct node{
int num;
node* next;
};

int main()
{
node* p1 = new node;
node* p2 = p1;
cout << &p1 << endl;
cout << &p2 << endl;
cout << p1 << endl;
cout << p2 << endl;
cout << (*(&p1)) << endl;
cout << (*(&p2)) << endl;
cout << (p1==p2) << endl;
cout << (&(*p1) ==&(*p2)) << endl;
return 0;
}


6.矩阵M
[m],元素的每行自左向右递增,每列的自上而下递增,现在给一个元素elem,编程实现它的查找,然后返回位置,如果没找到返回没有找到的提示信息。

答:杨氏矩阵。参考博客:/article/2939869.html

一面:

1.重新思考笔试第6道题,面试官给出一种从右上角的算法。所以笔试完也要把笔试题全部重新弄懂。

2.问项目,主要问了数据库和系统分析课的项目。系统设计分析让画领域模型、EA图等,还问那些对象之间的关系。

3.让面试官看了下最近在写的“坦克大战”游戏,讨论了一下C++的问题。

二面:

1.额,第一个问题是问我毕业论文写什么,当时不知道说什么,就只能说自然语言处理领域的。

2.让写下归并排序,很久没写了,一下子短路呢,要把排序都过一下。

3.关键的一题,问从5000W个int中找出top5,看过这种题,但没去深究过,就挂掉了。

4.后面的问题就随便问问了,问最深刻的书是什么,最喜欢哪门课,额,明显我喜欢的都是C++。

5.对了,还让描述了一下人工智能的项目。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: