CF786A - Berzerk
/*
CF786A - Berzerk
http://codeforces.com/contest/786/problem/A
博弈论
直接搜出NP状态图。记得要记忆化剪枝。
*
*/
#include <cstdio>
#include <cstring>
//#define tle
#ifdef tle
//#define test using namespace std;
const int Nmax=;
int now;
int is[][Nmax];
int n;
int s[][Nmax];
int tmp[][Nmax];
int k[];
#ifdef test
void watch()
{
for(int i=;i<=;i++)
{
printf("s[%d]:\n",i);
for(int j=;j<=n;j++)
printf("%d ",is[i][j]);
printf("\n");
}
}
#endif void work()
{
for(int j=;j<=;j++)
for(int i=;i<=k[j];i++)
{
int x=(n+-s[j][i])%n;
while(x<=)
x+=n;
is[j][x]=;
}
#ifdef test
watch();
#endif for(int t=;t<=;t++)
{
for(int ii=;ii<=;ii++)
for(int jj=;jj<=n;jj++)
tmp[ii][jj]=is[ii][jj];
for(int now=;now<=;now++)
for(int i=;i<=n;i++)
{
if(is[now][i]!=-)
continue;
int flag=;
for(int j=;j<=k[now];j++)
{
int x=(i+s[now][j])%n;
while(x<=)
x+=n;
if(is[now^][x]==)
{
is[now][i]=;
flag=;
break;
}
if(is[now^][x]==-)
flag=;//标记不是P态
}
if(!flag)
is[now][i]=;
#ifdef test
printf("is[%d][%d]:\n",now,i);
watch();
#endif }
int ff=;
for(int ii=;ii<=;ii++)
{
if(ff)
break;
for(int jj=;jj<=n;jj++)
if(tmp[ii][jj]!=is[ii][jj])
{
ff=;
break;
}
}
if(!ff)
break;
} } void init()
{
for(int i=;i<=n;i++)
is[][i]=is[][i]=-;
is[][]=is[][]=;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=;i++)
{
scanf("%d",&k[i]);
for(int j=;j<=k[i];j++)
scanf("%d",&s[i][j]);
}
init();
work();
for(int t=;t<=;t++)
{
for(int i=;i<=n;i++)
{
if(i!=)
printf(" ");
if(is[t][i]==-)
printf("Loop");
else if(is[t][i]==)
printf("Lose");
else
printf("Win");
}
printf("\n");
}
}
#endif using namespace std;
const int Nmax=;
int now;
int is[][Nmax];
int n;
int s[][Nmax];
int tmp[][Nmax];
int k[]; void dfs(int now,int x,int sstatus)
{
if(is[now][x]!=-)//如果已经有状态了,返回
return;
is[now][x]=sstatus;
if(sstatus==)//如果当前点为必败态,则让与其相接的点为必胜态
{
for(int i=;i<=k[now^];i++)
{
int next=(x-s[now^][i])%n;
while(next<=)
next+=n;
dfs(now^,next,);
}
}
if(sstatus==)//如果当前点为必胜态,则让与其相接的点的非必胜态边个数-1
{
for(int i=;i<=k[now^];i++)
{
int next=(x-s[now^][i])%n;
while(next<=)
next+=n;
tmp[now^][next]--;//利用tmp数组记录当前相接的点的非必胜态个数来剪枝,如果相邻点都是必胜态,则当前点为必败态
if(!tmp[now^][next])
dfs(now^,next,);
}
}
} void init()
{
for(int i=;i<=n;i++)
is[][i]=is[][i]=-;
is[][]=is[][]=;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=;i++)
{
scanf("%d",&k[i]);
for(int j=;j<=k[i];j++)
scanf("%d",&s[i][j]);
for(int j=;j<=n;j++)
tmp[i][j]=k[i];
}
init();
for(int j=;j<=;j++)
for(int i=;i<=k[j];i++)
{
int x=(n+-s[j][i])%n;
while(x<=)
x+=n;
dfs(j,x,);
}
for(int t=;t<=;t++)
{
for(int i=;i<=n;i++)
{
if(i!=)
printf(" ");
if(is[t][i]==-)
printf("Loop");
else if(is[t][i]==)
printf("Lose");
else
printf("Win");
}
printf("\n");
}
return ;
}
CF786A - Berzerk的更多相关文章
- [刷题]Codeforces 786A - Berzerk
http://codeforces.com/problemset/problem/786/A Description Rick and Morty are playing their own vers ...
- Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索
A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing ...
- [vjudge contest15(xjoi)] C - Berzerk
CodeForces - 787C Rick and Morty are playing their own version of Berzerk (which has nothing in comm ...
- cf786a
title: CodeForces 786A Berzerk data: 2018-3-3 10:29:40 tags: 博弈论 bfs 无限 with draw copyright: true ca ...
- Codeforces 786 A. Berzerk
题目链接:http://codeforces.com/problemset/problem/786/A 这个题出做$DIV2$的$C$以及$DIV1$的A会不会难了一点啊... 做法和题解并不一样,只 ...
- 【动态规划】Codeforces Round #406 (Div. 2) C.Berzerk
有向图博弈问题. 能转移到一个必败态的就是必胜态. 能转移到的全是必胜态的就是必败态. 转移的时候可以用队列维护. 可以看这个 http://www.cnblogs.com/quintessence/ ...
- Codeforces 786A Berzerk(博弈论)
[题目链接] http://codeforces.com/problemset/problem/786/A [题目大意] 有两个人,每个人有一个数集,里面有一些数,现在有一个环,有个棋子放在1, 有个 ...
- 【codeforces 787C】Berzerk
[题目链接]:http://codeforces.com/contest/787/problem/C [题意] 给你怪物一开始所在的位置; 然后两人轮流操作; 可以选择让这个怪物前进自己的集合里面所拥 ...
- Codeforces Round #406 (Div. 1)
B题打错调了半天,C题想出来来不及打,还好没有挂题 AC:AB Rank:96 Rating:2125+66->2191 A.Berzerk 题目大意:有一个东东在长度为n的环上(环上点编号0~ ...
随机推荐
- 6581 Number Triangle
6581 Number Triangle 时间限制:500MS 内存限制:1000K提交次数:57 通过次数:47 题型: 编程题 语言: G++;GCC Description 7 3 8 8 ...
- 在iOS开发中,我们会遇到十六进制和字符串之间相互转换,话不多说,直接上代码:
//将十六进制的字符串转换成NSString则可使用如下方式: + (NSString *)convertHexStrToString:(NSString *)str { if (!str || [s ...
- Node.js:创建第一个应用
ylbtech-Node.js:创建第一个应用 1.返回顶部 1. Node.js 创建第一个应用 如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 ...
- 一个 passive 引发的bug
不是什么很难的东西,权且做个记录. 首先说下背景,目前的项目中,需要同时绑定 wheel 和 scroll 事件. 绑定 wheel,目的是开发 ctrl + wheel 缩放页面功能,此功能与浏览器 ...
- Python+unittest 接口自动化测试
1.封装get.post#!/usr/bin/env python3# -*- coding: utf-8 -*- __author__ = 'hualai yu' import requests c ...
- LeetCode Weekly Contest 18B
1. 496. Next Greater Element I 暴力的话,复杂度也就1000 * 1000 = 1e6, 在1s的时限内完全可以. 当然,有许多优化方法,利用stack维护递减序列的方法 ...
- Hadoop MapReduce编程 API入门系列之wordcount版本3(七)
这篇博客,给大家,体会不一样的版本编程. 代码 package zhouls.bigdata.myMapReduce.wordcount3; import java.io.IOException; i ...
- guice 整合ninja framework(七)
ninja是一个优秀的,轻量级的mvc框架,它与google guice整合比较好.下面看一下例子: 我们在web.xml 配置一下: <listener> <listener-cl ...
- 打开word2010每次都要配置进度的解决办法
作者:朱金灿 来源:http://blog.csdn.net/clever101 不小心把ms office2010搞坏了,于是重装ms office2010,结果一打开word文档时总是出现下面的对 ...
- hdu1317 XYZZY Floyd + Bellman_Ford
这题,我在学搜索的时候做过.不过好像不叫这名字. 1.先用Floyd算法判断图的连通性.如果1与n是不连通的,输出hopeless. 2.用Bellman_Ford算法判断是否有正圈,如果某点有正圈, ...