[Bzoj 1874] [BeiJing2009 Wintercamp] Take the stone game "game theory | SG function "

Source: Internet
Author: User

Title Link: BZOJ-1874

Problem analysis

This is a combo game that is the and of many individual SG games.

That is, the total game is a combination of a number of single SG games, each SG game (that is, each heap of stones) between each other, each time from a single game to choose a decision, if all the individual game can not make a decision, the game failed.

There is a conclusion that SG (A + B + C ...) = SG (a) ^SG (B) ^SG (c) ...

This problem is not more than 1000 stones per heap, so can be [0, 1000] of the SG value of violence, using the definition of the most primitive SG function, sg (u) = MEX (SG (v)) E (U-V).

The SG value of each pile is then different or up. If you win, just enumerate all the initial scenarios in order and find the winning output and exit.

Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <  Algorithm> #include <cmath>using namespace Std;const int maxnum = + 5, MAXN = ten + 5;int N, M, mark_index;int A[MAXN], B[MAXN], Sg[maxnum], mark[maxnum];void calc_sg () {sg[0] = 0; Mark_index = 0;memset (mark, 0, sizeof), for (int i = 1; I <=, ++i) {++mark_index;for (int j = 1; j <= m; + +J) {if (B[j] > i) continue; MARK[SG[I-B[J]] = mark_index;} for (int j = 0; J <=, ++j) {if (mark[j]! = Mark_index) {Sg[i] = J; break;}}}}  int main () {scanf ("%d", &n), for (int i = 1; I <= n; ++i) scanf ("%d", &a[i]), scanf ("%d", &m), and for (int i = 1; I <= m; ++i) scanf ("%d", &b[i]); CALC_SG (); int temp = 0;for (int i = 1; I <= n; ++i) temp ^= sg[a[i]];if (temp = = 0) printf ("no\n"); else {printf ("yes\n" ); bool Flag = false;for (int i = 1; I <= n; ++i) {for (int j = 1; j <= m; ++j) {if (B[j] > A[i]) continue;if ((Te MP ^ Sg[a[i]] ^ sg[a[i]-B[J]]) = = 0) {Flag = true;printf ("%d%d\n", I, b[j]); if (Flag) break;}} return 0;}

  

[Bzoj 1874] [BeiJing2009 Wintercamp] Take the stone game "game theory | SG function "

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.