HDU 1517 A multiplication Game (game, SG function) __ Game

Source: Internet
Author: User

Topic Link: http://acm.hdu.edu.cn/showproblem.php?pid=1517

The beginning of a number is 1, two people take turns, each time you can multiply this number by 2-9, who finally get the number is not less than N, who wins.

Train of thought: Continue using the SG function method, here because the array is not sure how large, so the direct use of map storage. SG (1) for 0 will be defeated, or win.


#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
# include<iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
ll N;
Map<ll, Int> MP;

int sg (ll x) {
  if (x >= N) return 0;
  if (Mp.count (x)) return mp[x];
  Vector<ll> ha;
  for (int i = 2; I <= 9; i++) {
    ha.push_back (SG (x*i));
  Sort (Ha.begin (), Ha.end ());
  int c = 0, cur = 0;
  while (cur < ha.size ()) {
    if (c!= ha[cur]) {return
      mp[x] = c;
    }
    ++cur, ++c;
  }
  return mp[x] = ha[ha.size () -1]+1;
}

int main () {while
  (scanf ("%lld", &n) = = 1) {
    mp.clear ();
    if (SG (1LL)) printf ("Stan wins.\n");
    else printf ("Ollie wins.\n");
  }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.