[Original blog] poj 1067 stone game

Source: Internet
Author: User

Question Link
There are two piles of stones, which can be different in quantity. The game started with taking stones in turn by two people. The game stipulates that there are two different methods each time,One is to take away any number of stones in any pile; the other is to take away the same number of stones in both piles.Finally, the winner of all the stones. Now we will give you the initial number of two stones. If it is your turn to take them first, let us assume that both Parties adopt the best strategy and ask whether you are the winner or the loser at last. (Chinese questions, touching ing)

But this question is really haha.
There is no idea at the beginning. According to the definition of the mandatory victory status and the mandatory defeat status,n^3I typed a table and it looks like this.

The figure is 100x100, which has been reduced. The status is displayed in the upper left corner.(0,0)In the lower-right corner(100,100), Yellow indicates the defeat status. (Wow, it's nice to upload images to a blog ~)
Well, the symmetry is obvious, because the two stacks can be directly exchanged and seem regular.
T_t cannot find the rule.

Later I knew this was called"Wythoff game )". Encyclopedia
In this case, the defeat is called a singular situation (singular ~), Then you canFormulas availableIt seems that there is a half-cent relationship with the golden division. For details, refer to the encyclopedia.

RuleThe excerpt is as follows:

  • Any natural number is contained in one and only one singular situation.
  • Any operation can change a singular situation to a non-singular situation. (Mandatory)
  • An appropriate method can be used to convert a non-singular situation into a singular situation. (WINS)
  • If you use(ak,bk)Indicates a status, Setak<=bk, There area0=b0=0, AK is the minimum natural number that has not appeared before, andbk=ak+k.

Formula:ak =[k(1+√5)/2],bk= ak + k(K =, 2,..., n square brackets indicate the entire function ).
Practice: If (A, B) is a singular situation, there should bek=b-aThen, according to K, calculate the and other values that are not equal to the AK. If they are equal, the state is a singular situation, and the output is 0; otherwise, the output is 1.
* Rising posture.

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>//by zrt//problem:using namespace std;typedef long long LL;const int inf(0x3f3f3f3f);const double eps(1e-9); int main(){    #ifdef LOCAL    freopen("in.txt","r",stdin);    freopen("out.txt","w",stdout);    #endif    double sqrt5=sqrt(5.0);    int a,b;    while(~scanf("%d%d",&a,&b)){        if(a>b) swap(a,b);        int j=b-a;        int tmp=(int)(j*(1+sqrt5)/2.0);        if(tmp==a) puts("0");        else puts("1");    }    return 0;}
View code

 

[Original blog] poj 1067 stone 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.