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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索

發布時間:2023/12/14 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A. Berzerk

題目連接:

http://codeforces.com/contest/786/problem/A

Description

Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.

In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the others are planets. There's a monster in one of the planet. Rick and Morty don't know on which one yet, only that he's not initially in the black hole, but Unity will inform them before the game starts. But for now, they want to be prepared for every possible scenario.

Each one of them has a set of numbers between 1 and n?-?1 (inclusive). Rick's set is s1 with k1 elements and Morty's is s2 with k2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like x from his set and the monster will move to his x-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins.

Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game.

Input

The first line of input contains a single integer n (2?≤?n?≤?7000) — number of objects in game.

The second line contains integer k1 followed by k1 distinct integers s1,?1,?s1,?2,?...,?s1,?k1 — Rick's set.

The third line contains integer k2 followed by k2 distinct integers s2,?1,?s2,?2,?...,?s2,?k2 — Morty's set

1?≤?ki?≤?n?-?1 and 1?≤?si,?1,?si,?2,?...,?si,?ki?≤?n?-?1 for 1?≤?i?≤?2.

Output

In the first line print n?-?1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i?+?1 he wins, "Lose" if he loses and "Loop" if the game will never end.

Similarly, in the second line print n?-?1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Morty plays first and monster is initially in object number i?+?1 he wins, "Lose" if he loses and "Loop" if the game will never end.

Sample Input

5
2 3 2
3 1 2 3

Sample Output

Lose Win Win Loop
Loop Win Win Win

Hint

題意

有兩個人在一個環上玩游戲,由n個格子組成的環,其中0環是洞。

現在A,B兩個人各自擁有K[i]個選項,第i個選項是讓怪獸順時針走s[i]步。

兩個人輪流讓怪獸走,誰讓怪獸走進洞里面誰就勝利。

現在問你考慮所有情況,勝利的結果是什么。

題解:

記憶化搜索。

倒著來。dp[i][j]表示現在i先手位置在j的勝負情況。

顯然如果轉移到dp[i][j]的狀態全是對手勝利的話,那么dp[i][j]就是失敗。

如果轉移到dp[i][j]的狀態存在對手失敗,那么dp[i][j]就是勝利。

其他都是無限循環。

代碼

#include<bits/stdc++.h> using namespace std; const int maxn = 1e5+7; string Ans[3]={"Lose","Loop","Win"}; int n,Cnt[2],Flag[2][maxn],Times[2][maxn]; vector<int>Move[2]; void dfs(int x,int y,int val){Flag[x][y]=val;if(val==-1){for(int i=0;i<Move[!x].size();i++){if(!Flag[!x][(y+n-Move[!x][i])%n])dfs(!x,(y+n-Move[!x][i])%n,1);}}else{for(int i=0;i<Move[!x].size();i++){if(Flag[!x][(y+n-Move[!x][i])%n]){continue;}if(Times[!x][(y+n-Move[!x][i])%n]<Move[!x].size()){Times[!x][(y+n-Move[!x][i])%n]++;}if(Times[!x][(y+n-Move[!x][i])%n]==Move[!x].size()){dfs(!x,(y+n-Move[!x][i])%n,-1);}}} } int main(){scanf("%d",&n);for(int type=0;type<2;type++){scanf("%d",&Cnt[type]);for(int i=0;i<Cnt[type];i++){int tmp;scanf("%d",&tmp);Move[type].push_back(tmp);}}Flag[1][0]=-1;dfs(0,0,-1);dfs(1,0,-1);for(int type=0;type<2;type++){for(int i=1;i<n;i++){cout<<Ans[Flag[type][i]+1]<<" ";}cout<<endl;} }

轉載于:https://www.cnblogs.com/qscqesze/p/6628793.html

總結

以上是生活随笔為你收集整理的Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索的全部內容,希望文章能夠幫你解決所遇到的問題。

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