Welcome

首页 / 软件开发 / 数据结构与算法 / UVa 10465 Homer Simpson:枚举

UVa 10465 Homer Simpson:枚举2014-07-28 csdn博客 synapse7

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 possibleif (k % n == 0) ans2 = i + k / n;}if (drink) printf("%d %d
", ans1, drink);else printf("%d
", ans2);}return 0;}