Monkey Choosing King (Joseph is another way of implementation)

zhaozj2021-02-16  123

/ * Monkey Choose Principles: * Store the number of monkeys with array, indicating that monkeys are not selected * programs may have a problem, everyone finds a problem, tell me. * / # include

INT main () {Int i, position = 0, change, client = 0, n, m, monkey [30000]; scanf ("% D% D", & n, & m); // Initialization array for (i = 1 i <= n; i ) {monkey [i] = 0;}

Printf ("The Order: / N"); // The number of programs executed // The number of programs can be elastically controlled, and the final printing number must be the position of the king for (i = 1; i <= n; I ) {DO { position; if (position> n) {position = position% n;} if (monkey [position]! = 1) {Client ;}} while (client! = (m 2));

Change = (position> n) {change = change% n;} monkey [change] = 1; position = change; client = 0; printf ("% d", change);} printf ("/ N king is:% D, 呜 ... / n ", change); return (0);}

转载请注明原文地址:https://www.9cbs.com/read-8435.html

New Post(0)