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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

北邮OJ 1021. 16校赛-Stone Game

發(fā)布時(shí)間:2024/9/30 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 北邮OJ 1021. 16校赛-Stone Game 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

時(shí)間限制?4000 ms?內(nèi)存限制?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數(shù)值范圍10^5,且每個(gè)杯子的前序狀態(tài)包含多個(gè),不能使用一般的O(N^2)的getSG來(lái)做。用線段樹(shù)的維護(hù)區(qū)間最小值功能來(lái)更新SG值的所有者,SG值最大10^5,線段樹(shù)開(kāi)4倍空間,維護(hù)(更新)某一個(gè)SG值的當(dāng)前所有者(也就是用線段樹(shù)求SG值),然后我們會(huì)發(fā)現(xiàn)因?yàn)槊看沃荒芤苿?dòng)1個(gè)石子,而且每次都至少可以從當(dāng)前杯子移動(dòng)到前一個(gè)杯子(杯子序號(hào):偶數(shù)到奇數(shù),奇數(shù)到偶數(shù)),那么杯子里的石子數(shù)如果是偶數(shù),我們就可以不用考慮,不論你怎么從杯子里移動(dòng)出去,我們都可以照葫蘆畫瓢跟著你移動(dòng),對(duì)結(jié)果不影響。最后把杯子里石子數(shù)是奇數(shù)的SG值異或起來(lái)即可。


#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; }

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。