2010年9月16日 星期四

ACM 130 - Roman Roulette

#include <stdio.h>

int main()
{
while (1)
{
int n, k, i, s;
scanf("%d %d",&n ,&k);
if (n == 0 && k == 0) break;
int isLife[n], NO[n];
for (i = 0; i < n; i ++)
{
for (s = 0; s < n; s ++)
isLife[s] = 1, NO[s] = s + 1;
int nowSite = i, count = 0, nowLife = n;
while (nowLife != 1)
{
nowSite ++;
if (nowSite == n)
nowSite = 0;
if (isLife[NO[nowSite] - 1])
{
count ++;
if (count % (k-1) == 0)
{
isLife[NO[nowSite] - 1] = 0;
nowLife --, count = 0;
if (nowLife == 1) break;
int changeSite = nowSite, r;
while (1)
{
changeSite ++;
if (changeSite == n)
changeSite = 0;
if (isLife[NO[changeSite] - 1])
{
count ++;
if (count % k == 0)
{
r = NO[nowSite];
NO[nowSite] = NO[changeSite];
NO[changeSite] = r;
count = 0;
while (1)
{
nowSite ++;
if (nowSite == n)
nowSite = 0;
if (isLife[NO[nowSite] - 1])
break;
}
break;
}
}
}
}
}
}
if (isLife[0])
{
printf("%d\n", i + 1);
break;
}
}

}

return 0;
}

回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...