创新工场校园招聘笔试试题

时间:2018-12-31 12:00:00 资料大全 我要投稿

创新工场校园招聘笔试试题

   一, 选择题

创新工场校园招聘笔试试题

  1,求z的结果

  [cpp] view plaincopyprint?

  #define N 3

  #define Y(n) ((N+1)*n)

  z = 2*(N+Y(5+1));

  #define N 3

  #define Y(n) ((N+1)*n)

  z = 2*(N+Y(5+1));

  解答:48

  2,有关多线程,多进程的描述错误的是

  A, 子进程获得父进程的数据空间,堆和栈的复制品

  B, 线程可以与同进程的其他线程共享数据,但是它拥有自己的栈空间且拥有独立的执行序列

  C, 线程执行开销小,但是不利于资源管理和保护

  D, 进程适合在SMP机器上进行,而线程则可以跨机器迁移

  解答:D

  3,

  [cpp] view plaincopyprint?

  struct s

  { int x:3;

  int y:4;

  int z:5;

  double a;

  }

  struct s

  { int x:3;

  int y:4;

  int z:5;

  double a;

  }

  求sizeof(s)

  解答:

  16

  :是取位的作用,前三个变量是为两个字节,最后double变量是8个字节,

  结构体以8字节对齐,则为16字节,

创新工场校园招聘笔试试题

  4,序列{2,1,4,9,8,10,6,20}是某排序算法第二轮排序的结果,则该算法只能是

  A快速排序 B冒泡排序

  C选择排序 D插入排序

  解答:A

  5,我们需要监听一个事件状态,让它在状态发生改变时主动发出通知,请问需要哪种设计模式?

  A装饰者模式 B建造者模式

  C创新工场模式 D观察者模式

  解答:D

  6,有2012瓶矿泉水,其中有一瓶有毒,请问需要多少只老鼠才能一次性找到有毒的矿泉水?

  解答:11只

  二, 问答题

  1, 有0-n这n+1个数,但是其中丢了一个数,请问如何找出丢了哪个数?

  解答:

  求这n个数的sum,然后计算n(n+1)/2-sum可得。

  2, 解释

  [cpp] view plaincopyprint?

  #typedef char (*func)(int,char*)

  #typedef char (*func)(int,char*)

  解答:

  定义了一个函数指针的数据类型;

  该数据类型可以用来定义函数指针;

  定义的函数指针指向的`函数的参数为

  [cpp] view plaincopyprint?

  (int,char*)

  (int,char*)

  返回值为char型。

  3, 求输出结果

  [cpp] view plaincopyprint?

  int a[2][2][3]= { {{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}};

  int *ptr=(int *)(&a+1);

  printf(“%d %d”, *(int*)(a+1), *(ptr-1));

  int a[2][2][3]= { {{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}};

  int *ptr=(int *)(&a+1);

  printf(“%d %d”, *(int*)(a+1), *(ptr-1));

  解答:

  7 12 (已修定)

  考察多级指针,一定要明确指针指向的是什么,才能知道它加1后跳过了多少字节。

  &a是个四级指针,指向的是a这样的数组,所以它加1,就会跳过整个数组。

  4,求输出结果

  [cpp] view plaincopyprint?

  #include

  using namespace std;

  class A

  {

  public:

  virtual void print()

  { cout << "A::print()" <

  };

  class B: public A

  {

  public:

  virtual void print()

  { cout << "B::print()" <

  };

  class C: public A

  {

  public:

  virtual void print()

  { cout << "C::print()" <

  };

  void print(A a)

  {

  a.print();

  }

  void main()

  {

  A a,*aa,*ab,*ac;

  B b;

  C c;

  aa=&a;

  ab=&b;

  ac=&c;

  a.print();

  b.print();

  c.print();

  aa->print();

  ab->print();

  ac->print();

  print(a);

  print(b);

  print(c);

  }

  #include

  using namespace std;

  class A

  {

  public:

  virtual void print()

  { cout << "A::print()" <

  };

  class B: public A

  {

  public:

  virtual void print()

  { cout << "B::print()" <

  };

  class C: public A

  {

  public:

  virtual void print()

  { cout << "C::print()" <

  };

  void print(A a)

  {

  a.print();

  }

  void main()

  {

  A a,*aa,*ab,*ac;

  B b;

  C c;

  aa=&a;

  ab=&b;

  ac=&c;

  a.print();

  b.print();

  c.print();

  aa->print();

  ab->print();

  ac->print();

  print(a);

  print(b);

  print(c);

  }

  解答:

  A::print();

  B::print();

  C::print();

  A::print();

  B::print();

  C::print();

  A::print();

  A::print();

  A::print();

  三,算法编程题

  1,有1分,2分,5分,10分四种硬币,每种硬币数量无限,给定n分钱,求有多少种组合可以组合成n分钱?

  解答:

  思路:

  ①,四层循环

  ②,使用回溯法在空间中搜索

  代码为思路2:

  [cpp] view plaincopyprint?

  // chuangxingongchan.cpp : 定义控制台应用程序的入口点。

  //

  #include "stdafx.h"

  #include

  #include

  using namespace std;

  int count=0;

  int Target=0;

  int coin[4]={1,2,5,10};

  int total=0;

  vector solution;

  void dfs(int index)

  {

  if( total == Target )

  {

  count++;

  cout << count <<":" ;

  for( int i=0; i<(int)solution.size(); i++)

  {

  cout << solution[i]<<" ";

  }

  cout << endl;

  return;

  }

  if( total > Target )

  return;

  for( int i=index; i<4; i++)

  {

  total += coin[i];

  solution.push_back( coin[i] );

  dfs(i);

  solution.pop_back();

  total -=coin[i];

  }

  }

  int _tmain(int argc, _TCHAR* argv[])

  {

  while(1)

  {

  count=0;

  cin >> Target;

  dfs(0);

  cout << count <

  }

  return 0;

  }

  // chuangxingongchan.cpp : 定义控制台应用程序的入口点,

资料共享平台

创新工场校园招聘笔试试题》(https://www.unjs.com)。

  //

  #include "stdafx.h"

  #include

  #include

  using namespace std;

  int count=0;

  int Target=0;

  int coin[4]={1,2,5,10};

  int total=0;

  vector solution;

  void dfs(int index)

  {

  if( total == Target )

  {

  count++;

  cout << count <<":" ;

  for( int i=0; i<(int)solution.size(); i++)

  {

  cout << solution[i]<<" ";

  }

  cout << endl;

  return;

  }

  if( total > Target )

  return;

  for( int i=index; i<4; i++)

  {

  total += coin[i];

  solution.push_back( coin[i] );

  dfs(i);

  solution.pop_back();

  total -=coin[i];

  }

  }

  int _tmain(int argc, _TCHAR* argv[])

  {

  while(1)

  {

  count=0;

  cin >> Target;

  dfs(0);

  cout << count <

  }

  return 0;

  }

  2,马戏团里有个叠罗汉的表演,为了便于美观,下面的人身高和体重都要大于上面的人。现在知道n个演员的身高和体重,请问最多能叠多少层?

  解答:

  思路:

  首先生成一个有向图,用连接矩阵的方式来表示。

  map[i][j]==1表示第i个人上面可以放第j个人。

  然后开始对每个人进行深度搜索,这个图中不可能有环。

  所以对于每个人来说就是一棵树,搜索树的高度。

  再找出最高的高度即是答案。

  [cpp] view plaincopyprint?

  #include "stdafx.h"

  #include

  #include

  #include

  #include

  using namespace std;

  int N=0;

  double *weight;

  double *height;

  int **map;

  int maxDepth=0;

  vector bestPath;

  int dfs( int index, vector &path )

  {

  int flag=0;

  int depth = 0;

  vector bestPath;

  for( int i=0; i

  {

  if( map[index][i] != 0)

  {

  flag = 1;

  vector tPath;

  int t = dfs(i, tPath);

  if( t > depth )

  {

  path = tPath;

  depth = t;

  }

  }

  }

  if( flag==0 )

  {

  path.clear();

  path.push_back(index);

  return 1;

  }

  else

  {

  // path = bestPath;

  path.push_back(index);

  return depth+1;

  }

  }

  void CreateMap()

  {

  map = new int*[N];

  for( int i=0; i

  {

  map[i] = new int [N];

  memset( map[i], 0, N*sizeof(int) );

  }

  for( int i=0; i

  {

  for( int j=0; j

  {

  if( weight[j]

  map[i][j]=1;

  }

  }

  }

  void CreateData()

  {

  ofstream out( "in.txt" );

  int N = 30;

  out << N <

  for( int i=0; i

  out << rand() << " ";

  out << endl;

  for( int i=0; i

  out << rand() << " ";

  }

  int main()

  {

  CreateData();

  freopen( "in.txt", "r", stdin );

  cout << "Please input N:" <

  cin >> N;

  height = new double[N];

  weight = new double[N];

  for( int i=0; i

  cin >> height[i];

  for( int i=0; i

  cin >> weight[i];

  CreateMap();

  int depth=0;

  for(int i=0; i

  {

  vector tPath;

  int t=dfs(i,tPath);

  if( t>depth )

  {

  bestPath = tPath;

  depth = t;

  }

  }

  cout << depth <

  for( int i=0; i<(int)bestPath.size(); i++)

  {

  cout << height[bestPath[i]]<< " " << weight[bestPath[i]]<

  }

  return 0;

  }

【创新工场校园招聘笔试试题】相关文章:

1.创新工场笔试题

2.创新工场校招笔试题

3.微软校园招聘笔试题

4.google校园招聘笔试题

5.迅雷校园招聘笔试题

6.校园招聘笔试题目

7.网易校园招聘笔试题

8.小米校园招聘笔试题