"Game theory" poj2348 Euclid ' s game

Source: Internet
Author: User

Assume the current b>a.

First, B%a==0 win

Second, b<2*a, at present, we have no choice, if the next step is to win (finally to the situation one), the current will be defeated, on the contrary, the current victory.

Third, b>2*a, assuming X is the integer that makes the b-ax<a, consider subtracting a (x-1) from B, for example, minus 12 for (4,19).

At this point, the next state becomes the former said there is no choice of circumstances two, if the state is a must, the current state is the winning state.

If the status is a win state, the next step is the only certainty, so it is a must, so we can directly reach this state.

∴ situation Three is the winning state.

∴ first reached the situation one or three is to win.

#include <cstdio> #include <algorithm>using namespace Std;long long A,b;int main () {while (1)  {  scanf ("%lld%lld", &a,&b);  if (!a&&!b) break;  BOOL Flag=1;while (1)    {    if (a>b) swap (A, b);  if (b%a==0| | B> (a<<1))    {    puts (flag?) Stan wins ":" Ollie wins ");    break;    }  B-=a;  flag^=1;    }  } return 0;}

"Game theory" poj2348 Euclid ' s 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.