#include<cstdio> #include<iostream> #define db(a) cout << #a << " = " << a << endl; #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl; #define db3(a, b, c) cout << #a << " = " << a << " " << #b << " = " << b << " " << #c << " = " << c << endl; using namespace std; int lista[10000]; bool func_del(int a) { return a == -1; } int* borrar_si(int *ini, int *fin) { int *hasta = ini; for (; ini != fin; ini++) { if (!func_del(*ini)) *hasta++ = *ini; } return hasta; } int main() { int n, k, m; while ( scanf("%d%d%d", &n, &k, &m) ) { if (n == 0 && k == 0 && m == 0) break; for (int i = 0; i < n; i++) lista[i] = i + 1; int start = m - 1; int n2 = n; for (int i = 0; i < n - 1; i++) { lista[start] = -1; start += k; if(start >= n2) { start -= n2; n2 = borrar_si (lista, lista + n2) - lista; start %= n2; } } for (int i = 0; i < n2; i++) if(lista[i] != - 1) { printf("%d\n", lista[i]); break; } } return 0; }
miércoles, 19 de octubre de 2011
PKU 3517 And Then There Was One
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario