Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 源码及我错过的点，希望能有帮助。。

Posted by 1600017830 at 2017-01-12 13:22:00 on Problem 1012
```1.不是真的采用循环链表模拟，采用数学方法，利用取余来模拟踢出的过程；我们关心的只是好人还是坏人，原来的序号不重要，只要取余的余数小于k就是取到好人，break。
2.递增时要加k+1，而不是+1；
3.存数据，不存会超时。

#include<iostream>
using namespace std;
int finalans[30] = { 0 };//存储已经计算好的结果
int main()
{
int n = 0, m = 0, i = 0, judge = 1, judge2 = 1;
int ans = 0;
while (cin >> n&&n!=0)
{
if (finalans[n] == 0)
{
for (m = n;;m += n + 1)//尽可能快的递增
{
{
for (i = 0;i < n;i++)
{
ans = (m + ans) % (2 * n - i);//计算余数
if (ans < n)
{
judge = 0;
break;
}
}
ans = 0;
for (i = 0;i < n;i++)
{
ans = (m + 1 + ans) % (2 * n - i);
if (ans < n)
{
judge2 = 0;
break;
}
}
if (judge == 0 && judge2 == 0)
{
judge = 1;
judge2 = 1;
ans = 0;
continue;
}
else
{
if (judge == 1)
{
cout << m + 1 << endl;
finalans[n] = m + 1;
}
else if (judge2 == 1)
{
cout << m + 2 << endl;
finalans[n] = m + 2;
}
ans = 0;
break;
}
}
}
}
else
cout << finalans[n] << endl;
}
system("pause");
return 0;
}```

Followed by: