<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>

            陸游愛國名言

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

            陸游愛國名言

               一, 選擇題

            陸游愛國名言

              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?

              /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,馬戲團里有個疊羅漢的表演,為了便于美觀,下面的人身高和體重都要大于上面的人。現在知道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

              {

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

              }

            【陸游愛國名言】相關文章:

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

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

            愛國名言160句09-25

            愛國的勵志經典名言140句10-25

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

            外國愛國名言170句04-08

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

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

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

            作文素材:中國近代關于愛國的名言12-07

            • 相關推薦

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院