【题目链接】:http://codeforces.com/contest/787/problem/C

【题意】



给你怪物一开始所在的位置;

然后两人轮流操作;

可以选择让这个怪物前进自己的集合里面所拥有的数字所代表的步数;

对于2..n这些怪物的起点以及谁先进行游戏这些信息;

让这个怪物到位置1的人赢

判断谁能赢,输,或者游戏一直循环下去

【题解】



设f[i][j]表示i先玩,然后怪物一开始的位置为j的结果;

则

//-2表示输,-1表示赢,0表示不确定

f[1][1]=f[2][1]=-2;

即如果谁面临了怪物到达了1这个位置这个状态,他就输了;

因为这表示对方已经完成游戏了;

这样就代表先手输了;

然后对于这些为-2的状态;

可以往前推前一个人的状态;

即

前一个人,他走一步(通过自己集合里面的步数)到达了-2的状态;

也就是说让对方面临了先手输的状态,本来你是先手,然后你走一步,对方就变成先手啦,那么对方面临了先手输的状态,那么你就赢了;

因此对于所有能够走到-2的状态;

置其状态为先手赢;

然后再去找那些;

无论用集合里面哪个元素走,都会让对方面临先手赢状态的状态;

这些状态,置它们为先手输;

因为它们无论怎么走,对方都能面对先手赢的状态;

然后对于其他的状态,都是不确定.

写个倒推就好;

具体看代码



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 7e3+100; int k[3],n;
int s[3][N];
int g[3][N];
queue <pii> dl; void in()
{
rei(n);
rep1(i,1,2)
{
rei(k[i]);
rep1(j,1,k[i])
rei(s[i][j]);
}
} void get_ans()
{
dl.push(mp(1,1)),dl.push(mp(2,1));
g[1][1] = -2,g[2][1] = -2;
while (!dl.empty())
{
int f = dl.front().fi,x = dl.front().se;
int nex = 3-f;
dl.pop();
rep1(i,1,k[nex])
{
int y = x-s[nex][i];
if (y<=0)
y+=n;
if (g[f][x]==-2)
{
if (g[nex][y]!=-1)
{
g[nex][y] = -1;
dl.push(mp(nex,y));
}
}
else
{//g[f][x] = -1
if (g[nex][y]<0) continue;//如果已经确定了,就不用计数了
g[nex][y]++;//用来记录这个状态用集合里面的元素走一步会遇到多少个先手赢的状态,这里是直接在这个数组上计数,一数组两用
if (g[nex][y]==k[nex])//如果全都是先手赢,那么这个状态就是先手输
{
g[nex][y] = -2;
dl.push(mp(nex,y));
}
}
}
}
} void o()
{
rep1(i,2,n)
{
if (g[1][i]==-2)
printf("Lose");
else
if (g[1][i]==-1)
printf("Win");
else
printf("Loop");
if (i==n)
puts("");
else
putchar(' ');
}
rep1(i,2,n)
{
if (g[2][i]==-2)
printf("Lose");
else
if (g[2][i]==-1)
printf("Win");
else
printf("Loop");
if (i==n)
puts("");
else
putchar(' ');
}
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
in();
get_ans();
o();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 787C】Berzerk的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. How to Rotate Tomcat catalina.out

    If catalina.out becomes 2GB in size, tomcat crashes and fails to start without any error message. To ...

  2. Project Euler 516 5-smooth totients (数论)

    题目链接: https://projecteuler.net/problem=516 题目: \(5\)-smooth numbers are numbers whose largest prime ...

  3. Spring Profiles example--转载

    原文地址:http://www.mkyong.com/spring/spring-profiles-example/ Spring @Profile allow developers to regis ...

  4. less相关知识点

    less是一门css预处理语言,文件后缀名为.less,能减少css文件编写的代码量 官网 http://lesscss.cn/#using-less 安装 使用npm install -g less ...

  5. (转) 设置sqlplus中的退格键

    转自:http://blog.itpub.net/26110315/viewspace-717249/ 有些时候当你使用sqlplus登录到数据库中的时候,敲错了命令想要删除修改的时候,发现以前敲入的 ...

  6. cordova android

    Image.png Image.png http://www.jscss.cc/2016/10/18/cordova.html 装一个全局的cordova: 官网介绍:http://cordova.a ...

  7. Ruby(面向对象程序设计的脚本语言)入门

    Ruby是一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言. 简单介绍 Ruby 是开源的,在Web上免费提供,但须要一个许可证. Ruby 是一种通用的.解释的编程语言. Ruby 是 ...

  8. BaaS简介

    SaaS(软件即服务:Software as a Service).IaaS(基础设施即服务:Infrastructure as a Service)和PaaS(平台即服务:Platform as a ...

  9. android 指定时间加一个小时算法

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class My ...

  10. Altium Designer设置走线间距