HDU 1525 类Bash博弈
生活随笔
收集整理的這篇文章主要介紹了
HDU 1525 类Bash博弈
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
給兩數(shù)a,b,大的數(shù)b = b - a*k,a*k為不大于b的數(shù),重復(fù)過程,直到一個(gè)數(shù)為0時(shí),此時(shí)當(dāng)前操作人勝。
可以發(fā)現(xiàn)如果每次b=b%a,那么GCD的步數(shù)決定了先手后手誰勝,而每次GCD的一步過程視為一個(gè)子游戲,但是可以發(fā)現(xiàn)如果當(dāng)前可以約的次數(shù)大于2,那么此時(shí)操作的人可以控制局面,那么考慮所有可約次數(shù)大于2的即可。
?
/** @Date : 2017-10-12 21:46:31* @FileName: HDU 1525 類bash 博弈.cpp* @Platform: Windows* @Author : Lweleth (SoungEarlf@gmail.com)* @Link : https://github.com/* @Version : $Id$*/ #include <bits/stdc++.h> #define LL long long #define PII pair #define MP(x, y) make_pair((x),(y)) #define fi first #define se second #define PB(x) push_back((x)) #define MMG(x) memset((x), -1,sizeof(x)) #define MMF(x) memset((x),0,sizeof(x)) #define MMI(x) memset((x), INF, sizeof(x)) using namespace std;const int INF = 0x3f3f3f3f; const int N = 1e5+20; const double eps = 1e-8;int main() {int a, b;while(cin >> a >> b && (a || b)){int flag = 0;if(a < b)swap(a, b);while(a % b != 0 && b != 0){if(a / b > 1)//可約次數(shù)大于2 此時(shí)操作的人可以控制局面break;flag ^= 1;a -= b;swap(a, b);}printf("%s wins\n", flag?"Ollie":"Stan");}return 0; }轉(zhuǎn)載于:https://www.cnblogs.com/Yumesenya/p/7678916.html
總結(jié)
以上是生活随笔為你收集整理的HDU 1525 类Bash博弈的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新手入门Java疯狂讲义遇到的100个问
- 下一篇: adams功能区不显示_百科Esri大赛