2010年9月17日 星期五

ACM 10465 - Homer Simpson

#include <stdio.h>

int main()
{
int n, m, t, eatNum, i, recordT, recordI, tmp;
while (scanf("%d %d %d", &m, &n, &t) == 3)
{
recordI = 0;
if (m < n)
{
tmp = n;
n = m;
m = tmp;
}
eatNum = t / n;
t %= n;
recordT = t;
if (t)
{
for (i = 1; i <= eatNum; i ++)
{
if ((t + i*n) % m == 0)
{
t += i*n;
eatNum -= i;
break;
}
if ((t + i*n) % m < recordT)
{
recordI = i;
recordT = (t + i*n) % m;
}
}
if (recordI && t % m ) t += recordI * n, eatNum -= recordI;
eatNum += t / m;
t %= m;
}
printf("%d", eatNum);
if (t) printf(" %d", t);
printf("\n");
}
return 0;
}


回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...