日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

北邮OJ 1021. 16校赛-Stone Game

發布時間:2024/9/30 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 北邮OJ 1021. 16校赛-Stone Game 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

時間限制?4000 ms?內存限制?65536 KB

題目描述

? ? Alice and Bob are old friends in game theory. This afternoon they meet in Starbucks, each ordered a cup of coffee and decided to start a new game. They line?N?cups on the table, each containing?Ai?stones. Different from the usual stone games, each cup is numbered from?0?to?N?1, and has an integer?Ci?on it. The players in turn chooses one cup numbered?X?with stones and moves one stone to the cup numbered?Y?(Y{X?CX,X?CX+1,...,X?1}). Alice will be the first to move. The player who cannot move will lose the game. It is guaranteed that?1Cii?for any?i1, and?C0=0.

輸入格式

? ? The input starts with an integer?T?(1T20)? ? ? ?, indicating the number of test cases.
?? ?For each test case, the first line contains an integer?N?(1N100000)? ? ? ?indicating the number of cups. The second line contains?N?integers, the?i-th integer indicates?Ai?(0Ai109)? ? ? ? ,?the number of stones in cups. The third line contains?N?integers, the?i-th integer indicates?Ci,?the integers?written on the cups.

輸出格式

? ? For each test case, if Alice will win however Bob moves, print a line 'Win' without quotes. If not, print a line 'Lose' without quotes.

輸入樣例

2 3 0 0 1 0 1 1 7 2 1 0 0 0 1 0 0 1 2 1 2 4 3

輸出樣例

Lose Win 博弈題,典型求SG值異或出解,但本題n數值范圍10^5,且每個杯子的前序狀態包含多個,不能使用一般的O(N^2)的getSG來做。用線段樹的維護區間最小值功能來更新SG值的所有者,SG值最大10^5,線段樹開4倍空間,維護(更新)某一個SG值的當前所有者(也就是用線段樹求SG值),然后我們會發現因為每次只能移動1個石子,而且每次都至少可以從當前杯子移動到前一個杯子(杯子序號:偶數到奇數,奇數到偶數),那么杯子里的石子數如果是偶數,我們就可以不用考慮,不論你怎么從杯子里移動出去,我們都可以照葫蘆畫瓢跟著你移動,對結果不影響。最后把杯子里石子數是奇數的SG值異或起來即可。


#include<cstdio> #include<cmath> #include<algorithm> #define N 100050 using namespace std; int a[N]; int c[N]; int dat[N*4]; int sg[N];int init(int rot,int l,int r){dat[rot]=-1;if(l==r)return 1;int mid=(l+r)/2;init(rot*2,l,mid);init(rot*2+1,mid+1,r); } int inser(int rot,int pos,int x,int l,int r){if(l==r){dat[rot]=x;return 1;}int mid=(l+r)/2;if(pos<=mid)inser(rot*2,pos,x,l,mid);else inser(rot*2+1,pos,x,mid+1,r);dat[rot]=min(dat[rot*2],dat[rot*2+1]); } int q_min(int rot,int x,int l,int r){if(l==r){return l;}int mid=(l+r)/2;if(dat[rot*2]<x){return q_min(rot*2,x,l,mid);}else{return q_min(rot*2+1,x,mid+1,r);} }int main(){int t,n,i;for(scanf("%d",&t);t--;){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)scanf("%d",&c[i]);init(1,0,n);int sg_num=0;int i,j;for(i=0;i<n;i++){sg[i]=q_min(1,i-c[i],0,n);inser(1,sg[i],i,0,n);if(a[i]%2==1){sg_num=sg_num^sg[i];}}if(sg_num)printf("Win\n");else printf("Lose\n");}return 0; }

總結

以上是生活随笔為你收集整理的北邮OJ 1021. 16校赛-Stone Game的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。