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 记忆化搜索相关推荐

  1. Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索

    D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...

  2. Educational Codeforces Round 52: D. Three Pieces(记忆化搜索)

    D. Three Pieces 题意: 给你一n*n的矩阵,每个格子都有一个数字且所有数字构成一个1~n²的全排列,一开始你的棋子在编号为1的点上,之后你要依次到达编号为2的点.编号为3的点-- 编号 ...

  3. Codeforces Round #406 (Div. 1) A. Berzerk(博弈论)

    能转移到必败态的状态就是必胜态,只能转移到必胜态的状态就是必败态.反过来看,假设win[0][1]=win[1][1]=0,若当前为v,位置为now:(1)若win[v][now]=0,则win[v^ ...

  4. 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)...

    链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  5. Codeforces Round #406 (Div. 1) B. Legacy(线段树上优化建图)

    题意: 题解: 如何处理从v往[l−r][l-r][l−r]每个点进行连边? 如果暴力连边就有n2n^2n2条边,无法承受. 考虑如何优化区间建图. 线段树,它可以在区间询问/修改的时候,把一个区间分 ...

  6. 【扩展欧几里得】Codeforces Round #406 (Div. 2) A. The Monster

    扩欧,a+bx=c+dx,输出x>=0且y>=0,且a+bx最小的解. 要注意不能只保证x非负,还得看看能否保证y也非负. #include<cstdio> #include& ...

  7. Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs

    题目链接: http://codeforces.com/contest/525/problem/D 题意 给你一个n*m的田地,有一些*的地方是可以移除变成"."的,然后问你移除最 ...

  8. Codeforces Round #459 (Div. 2) C 思维,贪心 D 记忆化dp

    Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串. 给出一个字符串,有 (.). ? 三种字符, ? 可以 ...

  9. 思维dp ---- Codeforces Round #711 (Div. 2) - C. Planar Reflections[dp/记忆化搜索]

    题目链接 题目大意: 就是给你n个平面和一个寿命为k的衰变粒子.开始粒子从左向右飞行,粒子每经过一个平面就会产生一个副本粒子,这个副本粒子比原粒子的寿命少1,即为k-1,并且飞行方向是原粒子的反方向. ...

最新文章

  1. 字符串反转python_python字符串反转的四种方法详解
  2. C语言标准库之strcat函数
  3. java 泛型 恶心_Java的泛型原来这样让人不舒服
  4. 【CentOS7-Python系列】之一【VMwareWorkstation安装CentOS7】
  5. 拉文大学计算机科学,拉文大学
  6. python画一个祝福别人生日快乐_分享快乐给朋友的生日快乐祝福语生日贺卡句子...
  7. [摘抄]MySQL数据库系统的常规管理介绍
  8. 第九篇: 服务链路追踪(Spring Cloud Sleuth)(Finchley版本)
  9. python扫描器甄别操作系统类型_20189317 《网络攻防技术》 第三周作业
  10. 【今日CS 视觉论文速览】Fri, 1 Feb 2019
  11. 身陷 Bug 时,优秀的开发工程师是如何寻求帮助的?
  12. google支付接入PHP语言,PHP语言开发Paypal支付demo的具体实现
  13. 第10题 正则表达式匹配(动态规划)
  14. 穷人和富人在处事方式上的区别
  15. 新鲜出炉的自主协同操作系统研讨会纪要
  16. 百度输入法皮肤工具提示 CSS,百度手机输入法皮肤布局制作工具
  17. 六行shell脚本实现Android手机自动刷抖音极速版
  18. 如何让VR全景创业之路走得轻松?
  19. 1.3 Go语言上手-高质量编程与性能调优实战
  20. 【百度云破解】Proxyee Down使用

热门文章

  1. 财务管理与计算机论文,计算机小论文--浅论计算机与财务管理
  2. Day7 字符串详解——python学习之路
  3. 理解裸机部署过程ironic
  4. PET图像的SUV计算
  5. Dispatch barriers处理读与写的冲突
  6. java集合结构----集合框架以及背后的数据结构
  7. VIT Adapter【Vision Transformer Adapter for Dense Predictions】论文笔记
  8. 非真,亦非假——20世纪数学悖论入侵机器学习
  9. shader编程-三维场景下SDF建模,平滑交集、平滑并集、平滑差集(WebGL-Shader开发基础11)
  10. 三点法求点三维坐标实验