POJ 1704 Georgia and Bob (ladder game + proof)

Source: Internet
Author: User

POJ 1704 Topics Link

There are the following theorems about ladder game :

Treat all odd steps as n heap stones, make nim, move stones from odd heaps to even heaps as take stones, similarly, when the XOR value is not 0 (self-interest), the initiator will win.

Proof of theorem See this blog: http://blog.csdn.net/kk303/article/details/6692506

The following is the AC code for POJ 1704:

//The pawn can only go left (the leftmost line), can walk any Dogger (>=1)//and the pawn cannot cross the pawn in front of it (the pawn on its left)//each of the squares has a maximum of one piece, indicating that the piece can not go to the position of another piece//convert to Nim: Put the input position in order to calculate the spacing between two adjacent points, the spacing is the maximum number of steps to walk K, as a bunch of k stones//then iterate from the largest position (because of the right), calculating the Nim XOR value of the odd heap#include <iostream>#include<cstdio>#include<algorithm>using namespacestd;intMain () {intT; scanf ("%d",&t);  while(t--)    {        intsum=0, n,a[1005],b[1005]; scanf ("%d",&N); a[0]=0;  for(intI=1; i<=n;i++) scanf ("%d",&A[i]); Sort (A,a+n+1);  for(intI=1; i<=n;i++) B[i]=a[i]-a[i-1]-1; intCnt=0;  for(intI=n;i>0; i--) {CNT++; if(cnt&1) Sum^=B[i]; }        if(sum) printf ("Georgia'll win\n"); Elseprintf"Bob would win\n"); }    return 0;}

POJ 1704 Georgia and Bob (ladder game + proof)

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.