HDU 5996:dingyeye loves stone(階梯博弈)

來源:互聯網
上載者:User

標籤:map   log   efi   class   amp   typedef   ble   ios   std   

http://acm.hdu.edu.cn/showproblem.php?pid=5996

題意:在一棵樹上進行博弈,每次只能將當前的結點的石子放到父節點上,最後不能移動的輸。

思路:比賽的時候想的是對於每一個深度為dep的結點,可以轉化為dep堆同樣的深度為1的結點,然後就不會了,忘了最後異或起來偶數可以抵消,相當於對方移動,我方也跟著移動對方上一個回合移動的石子,所以最後只要考慮深度為奇數的結點。

 1 #include <cstdio> 2 #include <algorithm> 3 #include <iostream> 4 #include <cstring> 5 #include <string> 6 #include <cmath> 7 #include <queue> 8 #include <vector> 9 #include <map>10 using namespace std;11 #define INF 0x3f3f3f3f12 #define N 10001013 typedef long long LL;14 15 int fa[N], a[N], dep[N];16 17 int main()18 {19     int t;20     scanf("%d", &t);21     while(t--) {22         int n;23         scanf("%d", &n);24         int ans = 0;25         dep[0] = 0;26         for(int i = 1; i < n; i++)27             scanf("%d", &fa[i]);28         for(int i = 0; i < n; i++)29             scanf("%d", &a[i]);30         for(int i = 1; i < n; i++)31             dep[i] = dep[fa[i]] + 1;32         for(int i = 0; i < n; i++)33             if(dep[i] & 1) ans ^= a[i];34         if(ans) puts("win");35         else puts("lose");36     }37     return 0;38 }

 

HDU 5996:dingyeye loves stone(階梯博弈)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.