-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerCrisis.cpp
76 lines (66 loc) · 1.76 KB
/
powerCrisis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/***********************************************************
* @名称: 151 - Power Crisis (AC)
* @作者: Shawn
* @创建时间: 2017-11-19 20:13:16
* @修改人: Shawn
* @修改时间: 2017-11-19 20:13:16
* @备注: 约瑟夫问题
* @题目来源: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=87
***********************************************************/
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
//ifstream fin("powerCrisis.in");
//ofstream fout("powerCrisis.out");
while (true)
{
int total;
cin >> total;
if (total == 0)
{
break;
}
int m = 0;
while (true)
{
++m;
int nowPos = 0;
vector<bool> a(total, true);
bool ok = true;
for (int i = total; i >= 2; --i)
{
//fout << nowPos + 1 << " ";
a[nowPos] = false;
if (nowPos == 12)
{
ok = false;
break;
}
int myFind = 0, j = nowPos;
while (true)
{
j = (j + 1) % total;
if (a[j] == true)
{
++myFind;
}
if (myFind == m)
{
nowPos = j;
break;
}
}
}
if (ok == true)
{
break;
}
}
cout << m << endl;
}
return 0;
}