"POJ3537" crosses and crosses game, SG function, MULTI-SG game

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/vmurder/article/details/42654067

In fact, I just feel that the original traffic is a bit more uncomfortable than unauthorized piracy 233 ...

Test instructions: There is a one-dimensional chessboard, two people take turns to play chess, then who even three who wins.


Exercises

We consider a chessboard of length n, which, at I, is equivalent to converting the game into two game games (x-i-2) and i-3.


Cause: The left part will no longer work, and the right part will no longer be able to (say two exactly).

Then it becomes the current state of the two sub-states, and then the naked SG transferred.

MULTI-SG game means that a game can be converted into two sub-games.


Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 2015using namespace Std;int sg[n];int sg (int x) {if (x<0) return 0;if (sg[x]+1) return sg[x];bool vis[n]={0};int i;for (i= 1;i<=x;i++) VIS[SG (x-i-2) ^sg (i-3)]=true;for (i=0;vis[i];i++); return sg[x]=i;} int main () {//freopen ("test.in", "R", stdin), memset (sg,-1,sizeof sg); sg[0]=0,sg[1]=sg[2]=sg[3]=1;for (int x;scanf ("%d ", &x)!=eof;) printf ("%d\n ", SG (x)? 1:2); return 0;}



"POJ3537" crosses and crosses game, SG function, MULTI-SG game

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.