HDU 2188 悼念512汶川大地震遇難同胞——選拔志願者(巴什博弈論),hdu2188

來源:互聯網
上載者:User

HDU 2188 悼念512汶川大地震遇難同胞——選拔志願者(巴什博弈論),hdu2188

題目地址:HDU 2188

裸的巴什博弈模型。

當n=m+1時,由於一次最多隻能取m個,所以無論先取者拿走多少個,後取者都能夠一次拿走剩餘的物品,後者取勝,所以當一方面對的局勢是n%(m+1)=0時,其面臨的是必敗的局勢。所以當n=(m+1)*r+s,(r為任意自然數,s≤m)時,如果先取者要拿走s個物品,如果後取者拿走x(≤m)個,那麼先取者再拿走m+1-k個,結果剩下(m+1)(r-1)個,以後保持這樣的取法,那麼先取者肯定獲勝。總之,要保持給對手留下(m+1)的倍數,就能最後獲勝。

代碼如下:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int main(){    int t, n, m;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&m);        if(n%(m+1)==0)            puts("Rabbit");        else            puts("Grass");    }    return 0;}



悼念512汶川大地震遇難同胞——選拔志願者

假設條件不變,我判定是林對入選最後名單。
 
杭電acm2188

n%(m+1) 改成這個
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.