And Then There Was One(约瑟夫环)

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1883

题意:给3个整数 n,k,m (2 ≤ n ≤ 10000, 1 ≤ k ≤ 10000, 1 ≤ m ≤ n) 

代表,n个人围成一个圈,编号1-n 先删除m号,然后从m+1开始数,每 k 个删一次,然后就一直重复,问最后一个是几号

典型的约瑟夫环问题,递推

 1 #include<iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n,m,k;
 8     while (scanf("%d%d%d",&n,&k,&m)&&(n||m||k))
 9     {
10         int s = 0;
11         for (int i=2;i<=n-1;i++)
12             s = (s+k)%i;
13         s = (s+m)%n;
14         printf("%d
",s+1);
15     }
16     return 0;
17 }
View Code
原文地址:https://www.cnblogs.com/haoabcd2010/p/6670754.html