日本无码中文字幕片|日本精品在线观看无码视频|国产精品免费啪啪|Av无码一区二区|亚洲在线黄片免费观看|亚洲日韩中文字幕在线观看|熟女激情乱伦在线观看a黄片|成年人观看毛片网址|AV色色色色日韩性草|国产高清无码免费

陸游愛國名言

時間:2025-11-14 22:13:07 名言警句 我要投稿

陸游愛國名言

   一, 選擇題

陸游愛國名言

  1,求z的結(jié)果

  [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,有關(guān)多線程,多進程的描述錯誤的是

  A, 子進程獲得父進程的數(shù)據(jù)空間,堆和棧的復制品

  B, 線程可以與同進程的其他線程共享數(shù)據(jù),但是它擁有自己的棧空間且擁有獨立的執(zhí)行序列

  C, 線程執(zhí)行開銷小,但是不利于資源管理和保護

  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

 。菏侨∥坏淖饔,前三個變量是為兩個字節(jié),最后double變量是8個字節(jié),

  結(jié)構(gòu)體以8字節(jié)對齊,則為16字節(jié)。

  4,序列{2,1,4,9,8,10,6,20}是某排序算法第二輪排序的結(jié)果,則該算法只能是

  A快速排序 B冒泡排序

  C選擇排序 D插入排序

  解答:A

  5,我們需要監(jiān)聽一個事件狀態(tài),讓它在狀態(tài)發(fā)生改變時主動發(fā)出通知,請問需要哪種設(shè)計模式?

  A裝飾者模式 B建造者模式

  C創(chuàng)新工場模式 D觀察者模式

  解答:D

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

  解答:11只

  二, 問答題

  1, 有0-n這n+1個數(shù),但是其中丟了一個數(shù),請問如何找出丟了哪個數(shù)?

  解答:

  求這n個數(shù)的sum,然后計算n(n+1)/2-sum可得。

  2, 解釋

  [cpp] view plaincopyprint?

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

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

  解答:

  定義了一個函數(shù)指針的數(shù)據(jù)類型;

  該數(shù)據(jù)類型可以用來定義函數(shù)指針;

  定義的函數(shù)指針指向的函數(shù)的參數(shù)為

  [cpp] view plaincopyprint?

  (int,char*)

  (int,char*)

  返回值為char型。

  3, 求輸出結(jié)果

  [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后跳過了多少字節(jié)。

  &a是個四級指針,指向的是a這樣的數(shù)組,所以它加1,就會跳過整個數(shù)組。

  4,求輸出結(jié)果

  [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分四種硬幣,每種硬幣數(shù)量無限,給定n分錢,求有多少種組合可以組合成n分錢?

  解答:

  思路:

 、,四層循環(huán)

 、冢褂没厮莘ㄔ诳臻g中搜索

  代碼為思路2:

  [cpp] view plaincopyprint?

  /pic/p>

  /pic/p>

  #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;

  }

  /pic/p>

  /pic/p>

  #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,馬戲團里有個疊羅漢的表演,為了便于美觀,下面的人身高和體重都要大于上面的人,F(xiàn)在知道n個演員的身高和體重,請問最多能疊多少層?

  解答:

  思路:

  首先生成一個有向圖,用連接矩陣的方式來表示。

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

  然后開始對每個人進行深度搜索,這個圖中不可能有環(huán)。

  所以對于每個人來說就是一棵樹,搜索樹的高度。

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

  [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

  {

  /pic/p>

  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;

  }

【陸游愛國名言】相關(guān)文章:

愛國詩人陸游有趣的故事02-27

愛國的名言警句200句07-31

愛國名言160句09-25

愛國的勵志經(jīng)典名言140句10-25

愛國詩人陸游作文(通用18篇)05-21

外國愛國名言170句04-08

中國現(xiàn)代愛國名言(精選55句)07-05

關(guān)于愛國名言詩句(精選180句)09-27

少年愛國名言摘抄230句10-09

作文素材:中國近代關(guān)于愛國的名言12-07

  • 相關(guān)推薦