标签:int ret bsp and efi scanf names uva mes
约瑟夫环
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
标签:int ret bsp and efi scanf names uva mes
原文地址:http://www.cnblogs.com/w-h-h/p/7862941.html