• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

CodeforcesRound#406(Div.2)C.Berzerk

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
C. Berzerk
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
Input
5
2 3 2
3 1 2 3
Output
Lose Win Win Loop
Loop Win Win Win
Input
8
4 6 2 3 4
2 3 6
Output
Win Win Win Win Win Win Win
Lose Win Lose Lose Win Lose Lose
题目大意:Rick和Morty一起做游戏,他们分别有集合s1,s2,里面有k1,k2个数字。

现在在一个有1~n顺时针围城的圆环里,1号为黑洞色的山洞,2~n为植物深林,深林里有一个怪物。

Rick和Morty想把怪物移动到山洞里,他们可以使怪物顺时针移动x个单位,x为集合里的数字。

Rick和Morty轮流移动,最后把怪物移动到洞里算胜利。

问怪物分别在2~n,Rick和Morty分别处于先手,是否会有先手必胜、必败,或者处于循环。
题目解析:如果A无论怎么移动,使B下一步必胜,则A的现在状态为必败。
     如果A可以移动任意一步,使B下一步必败,则A现在的状态为必胜。
#include <bits/stdc++.h>

using namespace std;
const int N = 7005;
bool win[N][2], vis[N][2];
int k[2], n;
vector<int>a[2];
int cnt[N][2];

void slove(int Pre_point, int Player){
        vis[Pre_point][Player] = true;
        for(auto Mov_lenth: a[!Player]){
        int Now_point = (Pre_point-Mov_lenth+n)%n;

        if(Now_point == 0) continue;
        if(vis[Now_point][!Player]) continue;

        if(win[Pre_ponint][Player] && ++cnt[Now_point][!Player] == k[!Player])
            slove(Now_point, !Player);
        else if(!win[Pre_point][Player])
            win[Now_point][!Player] = true,
            slove(Now_point, !Player);
    }
}
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < 2; i++){
        scanf("%d", &k[i]);
        for(int j = 0, v; j < k[i]; j++){
            scanf("%d", &v);
            a[i].push_back(v);
        }
    }

    slove(0, 0);
    slove(0, 1);
    for(int i = 0; i < 2; i++){
        for(int j = 1; j < n; j++){
            if(!vis[j][i]) printf("Loop ");
            else printf("%s", win[j][i] > 0? "Win ":"Lose ");
        }
        printf("\n");
    }
    return 0;
}
View Code

 




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#后端调用WebApi地址发布时间:2022-07-13
下一篇:
[C#]-如何选择抽象基类与接口发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap