/*
Name: 约瑟夫环问题算法集锦
Copyright: 始发于goal00001111的专栏;允许自由转载,但必须注明作者和出处
Author: goal00001111搜集整理
Date: 03-12-08 18:14
Description:
有编号从1到N的N个人坐成一圈报数,报到M的人出局,下一位再从1开始, 如此持续,
直止剩下一位为止,报告此人的编号X。
输入N,M,求出X。
共搜集整理了7类10种算法,对于初学者和算法爱好者来说——看了绝对值!
*/
#include<iostream>
#include <time.h>
using namespace std;
int Fun_1(int n, int m);
int Fun_2(int n, int m);
int Fun_3(int n, int m);
int Fun_4(int n, int m);
int Fun_5(int n, int m);
int Fun_6(int n, int m);
int Fun_7(int n, int m);
int Fun_8(int n, int m);
int Fun_9(int n, int m);
int Fun_10(int n, int m);
int main(int argc, char* argv[])
{
int n, m;
//cout << "Input max, step: ";
// cin >> n >> m;
time_t startTime;
time_t endTime;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_1(i, 8);
time(&endTime);
cout << "No.1 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_2(i, 8);
time(&endTime);
cout << "No.2 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_3(i, 8);
time(&endTime);
cout << "No.3 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_4(i, 8);
time(&endTime);
cout << "No.4 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_5(i, 8);
time(&endTime);
cout << "No.5 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11;
Name: 约瑟夫环问题算法集锦
Copyright: 始发于goal00001111的专栏;允许自由转载,但必须注明作者和出处
Author: goal00001111搜集整理
Date: 03-12-08 18:14
Description:
有编号从1到N的N个人坐成一圈报数,报到M的人出局,下一位再从1开始, 如此持续,
直止剩下一位为止,报告此人的编号X。
输入N,M,求出X。
共搜集整理了7类10种算法,对于初学者和算法爱好者来说——看了绝对值!
*/
#include<iostream>
#include <time.h>
using namespace std;
int Fun_1(int n, int m);
int Fun_2(int n, int m);
int Fun_3(int n, int m);
int Fun_4(int n, int m);
int Fun_5(int n, int m);
int Fun_6(int n, int m);
int Fun_7(int n, int m);
int Fun_8(int n, int m);
int Fun_9(int n, int m);
int Fun_10(int n, int m);
int main(int argc, char* argv[])
{
int n, m;
//cout << "Input max, step: ";
// cin >> n >> m;
time_t startTime;
time_t endTime;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_1(i, 8);
time(&endTime);
cout << "No.1 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_2(i, 8);
time(&endTime);
cout << "No.2 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_3(i, 8);
time(&endTime);
cout << "No.3 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_4(i, 8);
time(&endTime);
cout << "No.4 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11; i++)
cout << Fun_5(i, 8);
time(&endTime);
cout << "No.5 time = " << difftime(endTime, startTime) << endl;
time(&startTime);
for (int i=10; i<11;