[vjudge contest15(xjoi)] C - 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 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
52 3 23 1 2 3
Lose Win Win LoopLoop Win Win Win
84 6 2 3 42 3 6
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"); ; }
[vjudge contest15(xjoi)] C - Berzerk的更多相关文章
- [XJOI NOI2015模拟题13] C 白黑树 【线段树合并】
题目链接:XJOI - NOI2015-13 - C 题目分析 使用神奇的线段树合并在 O(nlogn) 的时间复杂度内解决这道题目. 对树上的每个点都建立一棵线段树,key是时间(即第几次操作),动 ...
- [XJOI NOI2015模拟题13] B 最小公倍数 【找规律】
题目链接:XJOI - NOI2015-13 - B 题目分析 通过神奇的观察+打表+猜测,有以下规律和性质: 1) 删除的 n 个数就是 1~n. 2) 当 c = 2 时,如果 n + 1 是偶数 ...
- [XJOI NOI2015模拟题13] A 神奇的矩阵 【分块】
题目链接:XJOI NOI2015-13 A 题目分析 首先,题目定义的这种矩阵有一个神奇的性质,第 4 行与第 2 行相同,于是第 5 行也就与第 3 行相同,后面的也是一样. 因此矩阵可以看做只有 ...
- [XJOI NOI02015训练题7] B 线线线 【二分】
题目链接:XJOI - NOI2015-07 - B 题目分析 题意:过一个点 P 的所有直线,与点集 Q 的最小距离是多少?一条直线与点集的距离定义为点集中每个点与直线距离的最大值. 题解:二分答案 ...
- [刷题]Codeforces 786A - Berzerk
http://codeforces.com/problemset/problem/786/A Description Rick and Morty are playing their own vers ...
- Vjudge Code
Stylus @-moz-document url-prefix("https://cn.vjudge.net/"), url-prefix("https://vjudg ...
- Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索
A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing ...
- 专题[vjudge] - 数论0.1
专题[vjudge] - 数论0.1 web-address : https://cn.vjudge.net/contest/176171 A - Mathematically Hard 题意就是定义 ...
- 【XJOI】【NOI考前模拟赛7】
DP+卡常数+高精度/ 计算几何+二分+判区间交/ 凸包 首先感谢徐老师的慷慨,让蒟蒻有幸膜拜了学军的神题.祝NOI2015圆满成功 同时膜拜碾压了蒟蒻的众神QAQ 填填填 我的DP比较逗比……( ...
随机推荐
- SAP月末结账年结流程
SAP月末结账年结流程 SAP月末结账操作指南 流程描述:FI期末结帐流程包括应收帐款.应付帐款.固定资产.管理会计结帐.总帐结帐等一系列结帐过程,对于年结增加了余额结转及固定资产年度改变等动作,通过 ...
- HDU 6249 Alice’s Stamps(dp)
http://acm.hdu.edu.cn/showproblem.php?pid=6249 题意: 给出n个区间,求选k个区间的最大区间并. 思路: 可能存在左端点相同的多个区间,那么此时我们肯定选 ...
- spring boot配置druid数据源和监控配置
直接上代码: 一.pom.xml中添加依赖 <dependency> <groupId>com.github.drtrang</groupId> <artif ...
- ext4.2常用的几种弹框
以下记录了自己在做项目时,经常用到的几种ext弹框.项目中使用的ext是4.2版本的. 1. Ext.Msg.alert() 使用此种方式时,如果提示信息过长则提示信息会被覆盖掉一部分. Ext.Ms ...
- Grunt、Gulp区别 webpack、 requirejs区别
1. 书写方式 grunt 运用配置的思想来写打包脚本,一切皆配置,所以会出现比较多的配置项,诸如option,src,dest等等.而且不同的插件可能会有自己扩展字段,导致认知成本的提高,运用的时候 ...
- bat 命令 常用配置及其用法
1.初衷: bat 批处理文件:当我懒得一个个操作的时候,可以把若干东西放到一个文件里面,开机运行或者需要的时候手动运行.节省时间. 2.命令集说明 2.1 常用命令 2.1.0 help 命令 /? ...
- 基于iOS用CoreImage实现人脸识别
2018-09-04更新: 很久没有更新文章了,工作之余花时间看了之前写的这篇文章并运行了之前写的配套Demo,通过打印人脸特征CIFaceFeature的属性,发现识别的效果并不是很好,具体说明见文 ...
- 【C#】调用2.0踩过的坑
1.初始化[DllImport(“libarcsoft_face_engine.dll”, EntryPoint = “ASFInitEngine”, CallingConvention = Call ...
- java web 方面
1.Tomcat的优化经验. 2.http请求的GET与POST方式的区别. (1)get是从服务器上获取数据,post是向服务器传送数据. (2)get是把参数数据队列加到提交表单的ACTION属性 ...
- 通过TortoiseSVN进行文件(夹)外链 External File
1.假设将server/a.lua文件外链到client文件夹中 2.在client文件夹空白处右键->TortoiseSVN->Properties->New->Extern ...