# 11038: 【原1038】二哥的约瑟夫

### 题目描述

author: 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1038

……二哥一怒之下改了题目……

## Sample Input

``````5
1
2
3
4
``````

## Sample Output

``````4
``````

## FineArtz's solution

``````/* 二哥的约瑟夫 */
#include <iostream>
using namespace std;

int main(){
int m, k[10005];
cin >> m;
for (int i = 1; i < m; ++i)
cin >> k[i];
int ans = 0;
for (int i = 2; i <= m; ++i)
ans = (ans + k[m - i + 1]) % i;
cout << ++ans << endl;
return 0;
}
``````

## ligongzzz's solution

``````#include "iostream"
#include "vector"

using namespace std;

int main() {
int M, data[20000];
vector<int> monkeyList;
cin >> M;
for (int i = 0; i < M-1; i++)
cin >> data[i];
for (int i = 0; i < M; i++)
monkeyList.push_back(i+1);

for (int i = 0,current=0,len=M; i < M - 1; i++,len--) {
int temp = (data[i]+current-1) % len;
monkeyList.erase(monkeyList.begin()+temp);
current = temp;
}

cout << monkeyList.back();

return 0;
}
``````

## Neight99's solution

``````#include <iostream>

using namespace std;

int main() {
int M, *Kn, n = 0;

cin >> M;
Kn = new int[M];

Kn[0] = 0;
for (int i = 1; i < M; i++) {
cin >> Kn[i];
}

for (int i = 2; i < M + 1; i++) {
n = (n + Kn[M - i + 1]) % i;
}

cout << n + 1 << endl;

return 0;
}
``````

## WashSwang's solution

``````#include <iostream>
using namespace std;
int k[30000],t,f[30000];
int main() {
cin>>t;
f[1]=0;
for (int i=0;i<t-1;++i) cin>>k[i];
for (int i=2;i<=t;++i)
f[i]=(f[i-1]+k[t-i])%i;
cout<<f[t]+1;
}
``````

## yyong119's solution

``````#include <iostream>
using namespace std;
int K[10000]={0};
int main()
{
int M;
cin>>M;
int ans = 0;

for (int i = 1; i <= M-1; ++i){
cin>>K[i];
}

for (int i = 2; i <= M; ++i)
{
ans = (ans+K[M-i+1]) % i;
}
cout<<ans+1<<endl;
return 0;
}
``````