#include<stdio.h> #define max 1000000 int queue[max]; int e,f,r; void push(int i) { r++;e++; if(r>=max)r=1; queue[r]=i; } int pop() { e--; int i=queue[f]; f++; if(e>=max)f=1; return i; } int joshups(int n,int v) { register int i; e=n; for(i=1;i<=n;i++)queue[i]=i; f=1; r=n; i=0; if(n>1)pop(); while(e!=1) { if(i!=v) { i++; push(pop()); } else { pop(); i=0; } } return queue[f]; } int main() { int i,m; scanf("%d",&i); while(i) { m=1; if(i==13)printf("1\n"); else{ while((joshups(i,m++))!=13); printf("%d\n",m); } scanf("%d",&i); } return 0; }
Sunday, August 17, 2014
uva : 151 - Power Crisis
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment