A. Berzerk (SPFA博弈)

在一个类似于著名Berzerk游戏的版本中,瑞克和莫蒂正在玩一个需要巨大空间的游戏,他们使用电脑进行游戏。游戏中有n个按顺时针方向排列的对象,包括一个黑洞和其余的行星,其中一个行星上有一只怪物。玩家需要从他们的数字集合中选择一个数,使怪物移动到其当前位置后的第x个对象,目标是在不陷入无限循环的情况下将怪物引入黑洞。

A. Berzerk

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 k2elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like xfrom 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

由0开始SPFA,博弈

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int n;
int k[3];
int s[2][7005];
int ct[2][7005][5];
int dp[2][7005];
struct node
{
    int f,id,ty;
};
void spfa()
{
    node sta1,sta2;
    sta1.f=0,sta1.id=0,sta1.ty=3;
    sta2.f=1,sta2.id=0,sta2.ty=3;

    queue<node> q;
    q.push(sta1);
    q.push(sta2);

    while(!q.empty())
    {
        //cout<<"died"<<endl;
        node cur=q.front();
        q.pop();

        int f=cur.f;
        for(int i=0;i<k[1-f];i++)
        {
            int nf=1-f;
            int nid=(((cur.id-s[nf][i])%n)+n)%n;

            if(dp[nf][nid]!=0)
            {
                continue;
            }

            ct[nf][nid][cur.ty]++;

            if(ct[nf][nid][3]>0)
            {
                dp[nf][nid]=1;
                node nex;
                nex.f=nf,nex.id=nid,nex.ty=1;
                q.push(nex);
            }
            else if(ct[nf][nid][1]==k[nf])
            {
                dp[nf][nid]=3;
                node nex;
                nex.f=nf,nex.id=nid,nex.ty=3;
                q.push(nex);
            }
        }

    }

}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(ct,0,sizeof(ct));
        memset(dp,0,sizeof(dp));
        scanf("%d",&k[0]);
        for(int i=0;i<k[0];i++)
        {
            scanf("%d",&s[0][i]);
        }
        scanf("%d",&k[1]);
        for(int i=0;i<k[1];i++)
        {
            scanf("%d",&s[1][i]);
        }
        //cout<<"1"<<endl;
        spfa();
        //cout<<"2"<<endl;
        for(int i=1;i<n;i++)
        {
            if(dp[0][i]==0)
            {
                dp[0][i]=2;
            }
            int tp=dp[0][i];
            if(tp==1)
                printf("Win ");
            else if(tp==3)
                printf("Lose ");
            else
                printf("Loop ");
        }
        printf("\n");

        for(int i=1;i<n;i++)
        {
            if(dp[1][i]==0)
            {
                dp[1][i]=2;
            }
            int tp=dp[1][i];
            if(tp==1)
                printf("Win ");
            else if(tp==3)
                printf("Lose ");
            else
                printf("Loop ");
        }
        printf("\n");
    }
}

 

基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,并提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,并通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论分析与仿真验证相结合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值