UVALive - 3882:And Then There Was One
Posted white_hat_hacker
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVALive - 3882:And Then There Was One相关的知识,希望对你有一定的参考价值。
约瑟夫环
f[i]表示有i个人先处理第k个人,最后被处理的人是谁
#include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #define MAXN 10005 using namespace std; int f[MAXN]; int n,m,k; int main() { while(1){ scanf("%d%d%d",&n,&k,&m); if(!n)break; for(int i=2;i<=n;i++){ f[i]=(f[i-1]+k)%i; } printf("%d\n",((m-k+f[n])%n+n)%n+1); } return 0; }
以上是关于UVALive - 3882:And Then There Was One的主要内容,如果未能解决你的问题,请参考以下文章
UVALive 3882 And Then There Was One
F - Heron and His Triangle UVALive - 8206