CodeForces - 787C

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.

Example

Input
52 3 23 1 2 3
Output
Lose Win Win LoopLoop Win Win Win
Input
84 6 2 3 42 3 6
Output
Win Win Win Win Win Win WinLose Win Lose Lose Win Lose Lose

题目大意是:有n个位置1,2,3……n,围成1个圈,某个物体最开始的位置不在1,两个人轮流操作,每个人操作时可以让这个物体顺时针运动一些位置,使物体最终到达1号位置的人胜。求:物体初始在每个位置(不包括1),两个人分别先手的胜负情况。

感谢HX提供思路。。。

每个人每个状态无非就是三种情况:必胜(Win),必败(Lose),无法到达(Loop)。这其实是博弈论。

由于必败状态必定由所有必胜状态可推得,必胜状态只要1个必败状态就可以推出,那我们可以通过BFS/DFS的方式实现。设状态(x,y)表示当前是y操作,物体位置在x。那么(1,0)和(1,1)必然是必败状态。

假设我们使用BFS,当前状态为(ux,uy),下一个状态为(vx,vy),那么事实上是由(vx,vy)推得(ux,uy)。但是我们知道的是最终状态,求的是初始状态,所以要反着来推。

如果(vx,vy)这个状态还没有确定,则:

如果(ux,uy)必败,(vx,vy)必胜;

如果(ux,uy)必胜,则要看看其他状态(同一层的)是否全部必胜,若是,则(vx,vy)必败。

代码如下:
 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 #include<queue>
 using namespace std;
 ;
 struct node{
     int x,f;
 };
 ],a[][maxn],f[][maxn],cnt[][maxn];
 int read(){
     ,f=; char ch=getchar();
     '){if (ch=='-') f=-f; ch=getchar();}
     +ch-',ch=getchar();
     return x*f;
 }
 int main(){
     n=read();
     ; i<; i++){
         K[i]=read(); ; j<K[i]; j++) a[i][j]=read();
     }
     queue <node> Q; Q.push((node){,}); Q.push((node){,});
     memset(f,,][]=f[][]=;
     ; i<; i++)
         ; j<=n; j++) cnt[i][j]=K[i];
     for (; !Q.empty(); Q.pop()){
         node u=Q.front(),v; v.f=-u.f;
         ; i<K[v.f]; i++){
             v.x=u.x-a[v.f][i]; ) v.x+=n;
             if (f[v.f][v.x]) continue;
             ) f[v.f][v.x]=,Q.push((node){v.x,v.f});
             else{
                 cnt[v.f][v.x]--; ) f[v.f][v.x]=,Q.push((node){v.x,v.f});
             }
         }
     }
     ; i<; i++,putchar('\n'))
         ; j<=n; j++) printf(??"Win":"Lose");
     ;
 }

最新文章

  1. [LeetCode] Valid Word Square 验证单词平方
  2. #研发解决方案介绍#IdCenter(内部统一认证系统)
  3. AC日记——红与黑 codevs 2806
  4. 【leetcode】 search Insert Position(middle)
  5. JQuery Event属性说明
  6. iOS开发-图片高斯模糊效果
  7. Hark的数据结构与算法练习之鸡尾酒排序
  8. zkclient
  9. PHP7安装笔记
  10. NYOJ-469 擅长排列的小明 II AC 分类: NYOJ 2014-01-02 22:19 159人阅读 评论(0) 收藏
  11. winform 菜单项显示历史记录 分类: WinForm 2014-07-11 18:15 196人阅读 评论(0) 收藏
  12. Win7下VS2010使用STLPort 和boost1.56.
  13. zoj1797 Least Common Multiple 最小公倍数
  14. springBoot 随笔(二)
  15. Grafana报警--通知渠道配置
  16. scrum与第一次teamwork
  17. WebFrom 小程序【条件查询与分页整合】
  18. UVALive - 6436(DFS)
  19. Mysql 登录及用户切换、用户权限查询
  20. 早上STO单紧急寻源处理

热门文章

  1. MTP 写字机器
  2. 如何终止线程的运行(C/C++)
  3. django 配置 Django
  4. PostgreSQL安装及使用教程二(zip解压方式)
  5. arcpy导入错误 问题 “ImportError: No module named arcpy”
  6. ubuntu配置chrome git
  7. appium --log-timestamp &gt; appium.log
  8. 如何模拟一个http请求并把response的内容保存下载下来,导出到excel中(结尾福利)
  9. 验证码之SimpleCaptcha (二)
  10. Ubuntu下安装Google浏览器