We can easily observe that if the drawn number is in range [2, 9], Stan will win, and if it is in range [10, 18], Ollie will win. Suppose that one of Span's win range is [m, n], it can be extend to the next win range of [2*m+1, 2*9*n)]. Thus, the range width expands by a factor of 18. Then we can reduce the drawn number to the initial win ranges to check who will win the game.
Code:
- /*************************************************************************
- * Copyright (C) 2008 by liukaipeng *
- * liukaipeng at gmail dot com *
- *************************************************************************/
- /* @JUDGE_ID 00000 847 C++ "A Multiplication Game" */
- #include <algorithm>
- #include <cstdio>
- #include <cstring>
- #include <deque>
- #include <fstream>
- #include <iostream>
- #include <list>
- #include <map>
- #include <queue>
- #include <set>
- #include <stack>
- #include <string>
- #include <vector>
- using namespace std;
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
- freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
- #endif
- for (int n; scanf("%d", &n) == 1; ) {
- for (; n > 18; n = (n + 17) / 18) {}
- puts(n <= 9 ? "Stan wins." : "Ollie wins.");
- }
- return 0;
- }