亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 5.cpp

?? 《數據結構與程序設計》書本所有源代碼!!!!
?? CPP
字號:
/* Program extracts from Chapter 5 of   "Data Structures and Program Design in C++"   by Robert L. Kruse and Alexander J. Ryba   Copyright (C) 1999 by Prentice-Hall, Inc.  All rights reserved.   Extracts from this file may be used in the construction of other programs,   but this code will not compile or execute as given here. */// Section 5.1:int factorial(int n)/*Pre:  n is a nonnegative integer.Post: Return the value of the factorial of n.*/{   if (n == 0)      return 1;   else      return n * factorial(n - 1);}move(63,1,2,3); //  Move 63 disks from tower 1 to 2 (tower 3 temporary).cout << "Move disk 64 from tower 1 to tower 3."  << endl;move(63,2,3,1); //  Move 63 disks from tower 2 to 3 (tower 1 temporary).const int disks = 64;  // Make this constant much smaller to run program.void move(int count, int start, int finish, int temp);/*Pre:  None.Post: The simulation of the Towers of Hanoi has terminated.*/main(){   move(disks, 1, 3, 2);}void move(int count, int start, int finish, int temp){   if (count > 0) {      move(count - 1, start, temp, finish);      cout << "Move disk " << count << " from " << start           << " to " << finish << "." << endl;      move(count - 1, temp, finish, start);   }}move(1, 1, 2, 3); //  Move 1 disk from tower 1 to 2 (using tower 3).cout << "Move disk 2 from tower 1 to tower 3."  << endl;move(1, 2, 3, 1); //  Move 1 disk from tower 2 to 3 (using tower 1).move(0, 1, 3, 2); //  Move 0 disks.cout << "Move disk 1 from tower 1 to tower 2."  << endl;move(0, 3, 2, 1); //  Move 0 disks.// Section 5.2:void move(int count, int start, int finish, int temp)/*    move: iterative versionPre:  Disk count is a valid disk to be moved.Post: Moves count disks from start to finish using temp for temporary      storage.*/{   int swap;            //  temporary storage to swap towers   while (count > 0) {  //  Replace the if statement with a loop.      move(count - 1, start, temp, finish);  //  first recursive call      cout << "Move disk " << count << " from " << start           << " to " << finish << "." << endl;      count--;  //  Change parameters to mimic the second recursive call.      swap = start;      start = temp;      temp = swap;   }}int factorial(int n)/*    factorial: recursive versionPre:  n is a nonnegative integer.Post: Return the value of the factorial of n.*/{   if (n == 0) return 1;   else        return n * factorial(n - 1);}int factorial(int n)/*    factorial: iterative versionPre:  n is a nonnegative integer.Post: Return the value of the factorial of n.*/{   int count, product = 1;   for (count = 1; count <= n; count++)      product *= count;   return product;}int fibonacci(int n)/*    fibonacci: recursive versionPre:  The parameter n is a nonnegative integer.Post: The function returns the nth Fibonacci number.*/{   if (n <= 0)  return 0;   else if (n == 1)  return 1;   else              return fibonacci(n - 1) + fibonacci(n - 2);}int fibonacci(int n)/*    fibonacci: iterative versionPre:  The parameter n is a nonnegative integer.Post: The function returns the nth Fibonacci number.*/{   int last_but_one;   //  second previous Fibonacci number, F_i-2   int last_value;     //  previous Fibonacci number, F_i-1   int current;        //  current Fibonacci number F_i   if (n <= 0) return 0;   else if (n == 1) return 1;   else {      last_but_one = 0;      last_value = 1;      for (int i = 2; i <= n; i++) {         current = last_but_one + last_value;         last_but_one = last_value;         last_value = current;      }      return current;   }}// Section 5.3:int main()/*Pre:  The user enters a valid board size.Post: All solutions to the n-queens puzzle for the selected      board size are printed.Uses: The class Queens and the recursive function solve_from.*/{   int board_size;   print_information();   cout << "What is the size of the board? " << flush;   cin  >> board_size;   if (board_size < 0 || board_size > max_board)      cout << "The number must be between 0 and " << max_board << endl;   else {      Queens configuration(board_size); //   Initialize empty configuration.      solve_from(configuration);  //  Find all solutions extending configuration.   }}void solve_from(Queens &configuration)/*Pre:  The Queens configuration represents a partially completed      arrangement of nonattacking queens on a chessboard.Post: All n-queens solutions that extend the given configuration are printed.      The configuration is restored to its initial state.Uses: The class Queens and the function solve_from, recursively.*/{   if (configuration.is_solved()) configuration.print();   else      for (int col = 0; col < configuration.board_size; col++)         if (configuration.unguarded(col)) {            configuration.insert(col);            solve_from(configuration);   //   Recursively continue to add queens.            configuration.remove(col);         }}const int max_board = 30;class Queens {public:   Queens(int size);   bool is_solved() const;   void print() const;   bool unguarded(int col) const;   void insert(int col);   void remove(int col);   int  board_size; //   dimension of board = maximum number of queensprivate:   int  count;      //   current number of queens = first unoccupied row   bool queen_square[max_board][max_board];};void Queens::insert(int col)/*Pre:  The square in the first unoccupied row (row count) and column col      is not guarded by any queen.Post: A queen has been inserted into the square at row count and column      col; count has been incremented by 1.*/{   queen_square[count++][col] = true;}Queens::Queens(int size)/*Post: The Queens object is set up as an empty      configuration on a chessboard with size squares in each row and column.*/{   board_size = size;   count = 0;   for (int row = 0; row < board_size; row++)      for (int col = 0; col < board_size; col++)         queen_square[row][col] = false;}bool Queens::unguarded(int col) const/*Post: Returns true or false according as the square in the first      unoccupied row (row count) and column col is not guarded by any queen.*/{   int i;   bool ok = true; //   turns false if we find a queen in column or diagonal   for (i = 0; ok && i < count; i++)      ok = !queen_square[i][col];              //   Check upper part of column   for (i = 1; ok && count - i >= 0 && col - i >= 0; i++)      ok = !queen_square[count - i][col - i];  //  Check upper-left diagonal   for (i = 1; ok && count - i >= 0 && col + i < board_size; i++)      ok = !queen_square[count - i][col + i];  //  Check upper-right diagonal   return ok;}class Queens {public:   Queens(int size);   bool is_solved() const;   void print() const;   bool unguarded(int col) const;   void insert(int col);   void remove(int col);   int board_size;private:   int  count;   bool col_free[max_board];   bool upward_free[2 * max_board - 1];   bool downward_free[2 * max_board - 1];   int  queen_in_row[max_board];  //   column number of queen in each row};Queens::Queens(int size)/*Post: The Queens object is set up as an empty      configuration on a chessboard with size squares in each row and column.*/{   board_size = size;   count = 0;   for (int i = 0; i < board_size; i++) col_free[i] = true;   for (int j = 0; j < (2 * board_size - 1); j++) upward_free[j] = true;   for (int k = 0; k < (2 * board_size - 1); k++) downward_free[k] = true;}void Queens::insert(int col)/*Pre:   The square in the first unoccupied row (row count) and column col      is not guarded by any queen.Post: A queen has been inserted into the square at row count and column      col; count has been incremented by 1.*/{   queen_in_row[count] = col;   col_free[col] = false;   upward_free[count + col] = false;   downward_free[count - col + board_size - 1] = false;   count++;}bool Queens::unguarded(int col) const/*Post: Returns true or false according as the square in the first      unoccupied row (row count) and column col is not guarded by any queen.*/{   return  col_free[col]           && upward_free[count + col]           && downward_free[count - col + board_size - 1];}// Section 5.4:class Board {public:   Board();                    //  constructor for initialization   int done()  const;          //  Test whether the game is over.   void play(Move try_it);   int evaluate()  const;   int legal_moves(Stack &moves)  const;   int worst_case()  const;   int better(int value, int old_value) const; //  Which parameter does the mover prefer?   void print()  const;   void instructions()  const;/*  Additional methods, functions, and data will depend on    the game under consideration. */};int look_ahead(const Board &game, int depth, Move &recommended)/*Pre:  Board game represents a legal game position.Post: An evaluation of the game, based on looking ahead      depth moves, is returned.  The best move that can be found      for the mover is recorded as Move recommended.Uses: The classes Stack, Board, and Move, together with      function look_ahead recursively.*/{   if (game.done() || depth == 0)      return game.evaluate();   else {      Stack moves;      game.legal_moves(moves);      int value, best_value = game.worst_case();      while (!moves.empty()) {         Move try_it, reply;         moves.top(try_it);         Board new_game = game;         new_game.play(try_it);         value = look_ahead(new_game, depth - 1, reply);         if (game.better(value, best_value)) { //  try_it is the best move yet found            best_value = value;            recommended = try_it;         }         moves.pop();      }      return best_value;   }}//  class for a tic-tac-toe moveclass Move {public:   Move();   Move(int r, int c);   int row;   int col;};Move::Move()/*Post: The Move is initialized to an illegal, default value.*/{   row = 3;   col = 3;}Move::Move(int r, int c)/*Post: The Move is initialized to the given coordinates.*/{   row = r;   col = c;}class Board {public:   Board();   bool done() const;   void print() const;   void instructions() const;   bool better(int value, int old_value) const;   void play(Move try_it);   int worst_case() const;   int evaluate() const;   int legal_moves(Stack &moves) const;private:   int squares[3][3];   int moves_done;   int the_winner() const;};Board::Board()/*Post: The Board is initialized as empty.*/{   for (int i = 0; i < 3; i++)      for (int j = 0; j < 3; j++)         squares[i][j] = 0;   moves_done = 0;}void Board::play(Move try_it)/*Post: The Move try_it is played on the Board.*/{   squares[try_it.row][try_it.col] = moves_done % 2 + 1;   moves_done++;}int Board::the_winner() const/*Post: Return either a value of 0 for a position where neither player has won,      a value of 1 if the first player has won,      or a value of 2 if the second player has won.*/{   int i;   for (i = 0; i < 3; i++)      if (squares[i][0] && squares[i][0] == squares[i][1]                        && squares[i][0] == squares[i][2])            return squares[i][0];   for (i = 0; i < 3; i++)      if (squares[0][i] && squares[0][i] == squares[1][i]                        && squares[0][i] == squares[2][i])            return squares[0][i];   if (squares[0][0] && squares[0][0] == squares[1][1]                     && squares[0][0] == squares[2][2])            return squares[0][0];   if (squares[0][2] && squares[0][2] == squares[1][1]                     && squares[2][0] == squares[0][2])            return squares[0][2];   return 0;}bool Board::done() const/*Post: Return true if the game is over; either because a player has already won      or because all nine squares have been filled.*/{   return moves_done == 9 || the_winner() > 0;}int Board::legal_moves(Stack &moves) const/*Post: The parameter Stack moves is set up to contain all      possible legal moves on the Board.*/{   int count = 0;   while (!moves.empty()) moves.pop();   for (int i = 0; i < 3; i++)      for (int j = 0; j < 3; j++)         if (squares[i][j] == 0) {            Move can_play(i,j);            moves.push(can_play);            count++;         }   return count;}int Board::evaluate() const/*Post: Return either a value of 0 for a position where neither player has won,      a positive value between 1 and 9 if the first player has won,      or a negative value between -1 and -9 if the second player has won,*/{   int winner = the_winner();   if (winner == 1) return 10 - moves_done;   else if (winner == 2) return moves_done - 10;   else return 0;}/*************************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
乱一区二区av| 五月婷婷另类国产| 成人黄页在线观看| 亚洲国产精华液网站w| 成人免费视频免费观看| 亚洲私人黄色宅男| 色8久久精品久久久久久蜜| 亚洲一区二区三区视频在线| 欧美色综合影院| 日韩福利电影在线| 欧美精品一区二区三区高清aⅴ| 狠狠网亚洲精品| 国产日韩欧美激情| 91久久精品国产91性色tv| 一区二区三区不卡视频| 欧美精品在线视频| 黄色小说综合网站| 国产精品网站导航| 欧美日韩在线不卡| 韩国中文字幕2020精品| 国产精品国产三级国产aⅴ原创| 91国偷自产一区二区三区观看| 日韩在线a电影| 国产午夜精品在线观看| 91免费在线视频观看| 婷婷成人激情在线网| 精品国产一区久久| 一本一道久久a久久精品| 日韩成人av影视| 中文字幕成人在线观看| 欧美影院精品一区| 国产一区久久久| 一区二区激情视频| 久久香蕉国产线看观看99| 色婷婷综合久久久中文一区二区 | 国产高清成人在线| 亚洲精品成人精品456| 精品久久久久久久久久久久包黑料| 国产成人精品影院| 视频一区在线视频| 亚洲婷婷综合久久一本伊一区 | 日韩视频国产视频| 色综合久久综合网97色综合 | 中文子幕无线码一区tr| 91精品在线观看入口| 99久久99精品久久久久久| 另类中文字幕网| 亚洲国产精品久久不卡毛片 | av日韩在线网站| 激情国产一区二区| 天堂av在线一区| 亚洲欧美日韩在线| 国产欧美精品一区二区三区四区| 666欧美在线视频| 一本色道久久综合亚洲精品按摩| 国产精品一区二区久久精品爱涩| 午夜激情综合网| 亚洲另类色综合网站| 国产精品嫩草影院av蜜臀| 日韩欧美在线综合网| 欧美怡红院视频| 一本一道久久a久久精品| 国产精品中文字幕日韩精品| 麻豆精品一区二区av白丝在线| 亚洲自拍与偷拍| 国产精品不卡视频| 欧美—级在线免费片| 久久久精品一品道一区| 欧美tk—视频vk| 精品日韩成人av| 欧美变态凌虐bdsm| 欧美一级免费大片| 91精品久久久久久久91蜜桃| 欧美性三三影院| 91国产精品成人| 在线观看免费成人| 欧美日韩一级大片网址| 在线免费观看日本一区| 欧美在线制服丝袜| 欧美影院精品一区| 欧美老人xxxx18| 91精品国产91久久综合桃花| 欧美日韩不卡在线| 7777精品伊人久久久大香线蕉的 | 精品一区二区在线视频| 日韩精品亚洲专区| 蜜桃一区二区三区四区| 麻豆成人综合网| 国产精品一区二区三区四区| 国产成人av一区二区三区在线| 国产精品一区二区久久精品爱涩| 国产福利精品导航| 91小视频在线| 欧美羞羞免费网站| 欧美一区二区三区在线视频 | 91在线精品一区二区三区| 91同城在线观看| 91国偷自产一区二区开放时间 | 久久精品亚洲一区二区三区浴池| 久久久久久久久久久久久久久99| 久久青草欧美一区二区三区| 国产精品私人影院| 亚洲午夜私人影院| 五月天视频一区| 国产精品一区二区无线| 色哟哟精品一区| 欧美一区二区三区不卡| 久久久久国产精品麻豆| 亚洲日本在线a| 蜜芽一区二区三区| 欧美色图免费看| 欧美大片日本大片免费观看| 日本一区二区三区在线观看| 亚洲免费观看高清完整版在线| 天天亚洲美女在线视频| 国产成人综合亚洲网站| 色综合视频一区二区三区高清| 欧美日韩国产电影| 国产欧美日韩精品a在线观看| 亚洲一区av在线| 精品亚洲成av人在线观看| 成人黄页在线观看| 91精品国产91久久久久久最新毛片| 久久女同性恋中文字幕| 亚洲精品久久久蜜桃| 久久99精品久久久久久| 成人sese在线| 欧美日韩一级二级| 国产精品成人在线观看| 奇米影视一区二区三区小说| 91麻豆产精品久久久久久| 日韩亚洲电影在线| 亚洲靠逼com| 国产v日产∨综合v精品视频| 欧美一区二区视频在线观看 | 久久久精品中文字幕麻豆发布| 亚洲精品乱码久久久久久| 国产精品一级黄| 欧美精品1区2区3区| 最新热久久免费视频| 国产综合久久久久影院| 精品视频资源站| 国产精品久久二区二区| 国内精品第一页| 91精品在线一区二区| 洋洋av久久久久久久一区| 成人av在线播放网站| 久久综合色综合88| 美日韩一区二区三区| 欧美日韩一区视频| 一区二区欧美国产| 91在线观看下载| 国产欧美日韩久久| 国产成人综合网站| 久久久天堂av| 国产一区二区三区四区五区美女| 欧美一级艳片视频免费观看| 亚洲国产wwwccc36天堂| 在线观看视频91| 亚洲狠狠丁香婷婷综合久久久| av亚洲精华国产精华精| 国产精品久久久久久久久快鸭 | 亚洲视频香蕉人妖| 97久久精品人人澡人人爽| 国产精品久久久久久久久免费相片| 国产精品18久久久久| 欧美精品一区二区三| 国产精品一区免费在线观看| 日韩精品一区二区三区视频播放| 日韩高清中文字幕一区| 欧美一级视频精品观看| 久久成人麻豆午夜电影| 日韩欧美亚洲一区二区| 精品一区二区久久| 久久久精品日韩欧美| 成人深夜在线观看| 亚洲三级在线播放| 在线免费亚洲电影| 午夜精品久久久久久久久久久 | 亚洲一区在线看| 欧美日韩精品欧美日韩精品一| 婷婷久久综合九色国产成人| 日韩三区在线观看| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 国产综合色产在线精品| 国产视频一区二区三区在线观看| 成人h动漫精品一区二区| 国产精品家庭影院| 欧美日韩高清影院| 另类成人小视频在线| 欧美韩日一区二区三区四区| 不卡电影免费在线播放一区| 亚洲国产婷婷综合在线精品| 91.麻豆视频| 国产精品资源网| 亚洲桃色在线一区| 欧美一区二区三区喷汁尤物| 国产福利精品一区| 亚洲一区二区三区小说| 欧美一区二区日韩|