13個人中找出叛徒的問題(耶穌問題)經典做法,叛徒耶穌

來源:互聯網
上載者:User

13個人中找出叛徒的問題(耶穌問題)經典做法,叛徒耶穌
//耶穌有13個門徒,其中有一個就是出賣耶穌的叛徒,請用排除法找出這位叛徒:13人圍坐一圈,從第一個開始報號:1,2,3,1,2,3...。凡是報到“3”就退出圈子,最後留在圈子內的人就是出賣耶穌的叛徒。請找出它原來的序號
    
    
//        int a[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
//        int  number = 13, i = 0, count = 0;//number用來記錄剩下大不是0的數,count值為1, 2,  3
//        while (number > 1) {
//            if (a[i] != 0) {
//                count ++;
//            }
//            if (count == 3) {
//                a[i] = 0;
//                count = 0;
//                number --;
//            }
//                i ++;
//            if (i == 13) {
//                i = 0;
//            }
//            }
//        for ( i = 0; i < 13; i++) {
//            if (a[i] > 0) {
//                printf("%d", a[i]);
//            }
//        }
編程題:耶穌有13個門徒,其中有一個就是出賣耶穌的叛徒,用排除法找出這位叛徒:13人圍坐一圈,從第一

這個排版實在是沒人會幫你看。
 
耶穌有13個門徒,其中有一個就是出賣耶穌的叛徒,用排除法找出這位叛徒:

丟手絹演算法
/////////////////////////////////////////
// 魔比斯環演算法 /
// n個人,從第k個人開始數,數到a的離開 /
// 問你最後一個離開的是誰,或者所有的 /
// 人離開順序 /
/////////////////////////////////////////
#include <iostream>
using namespace std;
class Moebius {
private:

int* place;
int n; //圈內人數
int k; //從第k個人報數
int a; //報數的終止值(從1 - a報數)
void delPlace(int); //報數為a的人離開環
public:
Moebius (){}; //無參建構函式
Moebius ( int, int, int );//建構函式
void Moebius::listInit (); // 得到環的原始順序列表
void Moebius::listMove ();//得到環的出圈順序
};
Moebius::Moebius ( int _n, int _k, int _a ) { // 定義建構函式
int i;
n = _n;
k = _k;
a = _a;
place = new int[n];
for ( i = 0; i < n; i++ )
place[i] = i + 1;
}

void Moebius::listInit () { // 輸出環內人員原始順序列表
int i;
cout << "魔比斯環初始人員順序列表:" << endl;
for ( i = 0; i < n; i++ )
cout << " " << place[i];
cout << endl;
}
void Moebius::listMove () { //輸出環內人員離開順序
int iPlace = k - 1; //確定第一個報數的人的位置

cout << "魔比斯環內的人離開順序列表:" << endl;

while ( n ) { //直到環內沒人為止
iPlace = (iPlace ......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.