poj 3517

让我蛋疼一下午的约瑟夫环。。

//============================================================================
// Name        : 3517.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;




int n, m, k, s, ans, t, p;

int main(){
	freopen("a.txt", "r", stdin);
	while(scanf("%d%d%d", &n, &m, &k)&&(n||m||k)){
//		printf("%d\n", p);
		s = 0;
		for(int i = 2;i < n;i++){
			s = (s+m)%i;
		}
		ans = (s+k)%n+1;
		if(ans == 0) ans = n;
		printf("%d\n", ans);
	}
	return 0;
}

  

posted @ 2011-07-25 20:08  KOKO's  阅读(118)  评论(0编辑  收藏  举报