UVa Problem Solution: 847 - A Multiplication Game


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:
  1. /*************************************************************************
  2.  * Copyright (C) 2008 by liukaipeng                                      *
  3.  * liukaipeng at gmail dot com                                           *
  4.  *************************************************************************/
  5. /* @JUDGE_ID 00000 847 C++ "A Multiplication Game" */
  6. #include <algorithm>
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <deque>
  10. #include <fstream>
  11. #include <iostream>
  12. #include <list>
  13. #include <map>
  14. #include <queue>
  15. #include <set>
  16. #include <stack>
  17. #include <string>
  18. #include <vector>
  19. using namespace std;
  20.           
  21. int main(int argc, char *argv[])
  22. {
  23. #ifndef ONLINE_JUDGE
  24.   freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
  25.   freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
  26. #endif
  27.   for (int n; scanf("%d", &n) == 1; ) { 
  28.     for (; n > 18; n = (n + 17) / 18) {}
  29.     puts(n <= 9 ? "Stan wins." : "Ollie wins.");
  30.   }
  31.   return 0;
  32. }

發佈了69 篇原創文章 · 獲贊 2 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章