HDU - 5978 To begin or not to begin(简单博弈)
生活随笔
收集整理的這篇文章主要介紹了
HDU - 5978 To begin or not to begin(简单博弈)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:給出k個黑球以及一個紅球,兩個人輪流摸球,摸到紅球算贏,問先手有優勢還是后手有優勢還是都一樣,若先手優勢輸出1,若后手優勢輸出2,若都一樣輸出0
題目分析:簡單博弈,我們只要將前幾種情況討論一下答案就出來了:
如此往復,我們可以發現進入了一個循環,那么循環的關鍵就是k的奇偶,當k為奇數時我們輸出0,當k為偶數時我們輸出1即可
#include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cstring> #include<algorithm> #include<stack> #include<queue> #include<map> #include<sstream> using namespace std;typedef long long LL;const LL inf=0x3f3f3f3f3f3f3f3f;const int N=15;int main() { // freopen("input.txt","r",stdin);int n;while(scanf("%d",&n)!=EOF)printf("%d\n",n&1?0:1);return 0; }?
總結
以上是生活随笔為你收集整理的HDU - 5978 To begin or not to begin(简单博弈)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: qduoj - WHY吃糖果(二分套二分
- 下一篇: POJ - 2689 Prime Dis