UVa 10465 Homer Simpson (枚举)

10465 - Homer Simpson

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=1406


这数据量。。枚举绝对是最快的方式了。


完整代码:

/*0.025s*/



#include<bits/stdc++.h>

using namespace std;



int main()

{

	int m, n, t, x, ans1, ans2, drink, i, k;

	while (~scanf("%d%d%d", &m, &n, &t))

	{

		if (m > n) swap(m, n);

		x = t / m, drink = -1u>>1;

		for (i = x; i >= 0 && drink; --i)///枚举

		{

			k = t - i * m;

			if (drink > k % n) drink = k % n, ans1 = i + k / n;///drinks as little beer as possible

			if (k % n == 0) ans2 = i + k / n;

		}

		if (drink) printf("%d %d\n", ans1, drink);

		else printf("%d\n", ans2);

	}

	return 0;

}

 

 

 

你可能感兴趣的:(home)