CF 1033 C. Permutation Game
C. Permutation Game
http://codeforces.com/contest/1033/problem/C
题意:
一个排列,每个位置i走到的位置j满足:a[j]>a[i],(j-i)是a[i]的倍数。问从每个位置开始,是否有必胜策略。
分析:
博弈论+拓扑。
由于是一个排列,那么可以枚举每个数,判断这个位置的a是否大于它,如果可以连边。这样的复杂度是$nlogn$的。
然后对于一些无路可走的点,这是必败态,根据必胜和必败的定义:必胜态的后继状态中存在至少一个必败态,必败态的后继状态全是必胜态。
然后建反图,在DAG上拓扑。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
int a[N], deg[N], q[N], f[N];
vector<int>T[N]; int main() {
int n = read();
for (int i=; i<=n; ++i) a[i] = read(); for (int i=; i<=n; ++i) {
for (int j=i+a[i]; j<=n; j+=a[i])
if (a[j] > a[i]) T[j].push_back(i), deg[i] ++;
for (int j=i-a[i]; j>=; j-=a[i])
if (a[j] > a[i]) T[j].push_back(i), deg[i] ++;
} int L = , R = ;
memset(f, -, sizeof(f));
for (int i=; i<=n; ++i)
if (!deg[i]) q[++R] = i, f[i] = ; while (L <= R) {
int u = q[L ++];
for (int sz=T[u].size(),i=; i<sz; ++i) {
int v = T[u][i];
if (f[v] == -) {
if (f[u] == ) f[v] = ;
else f[v] = ;
}
else {
if (f[u] == ) f[v] = ;
}
deg[v] --;
if (!deg[v]) q[++R] = v;
}
}
for (int i=; i<=n; ++i) {
if (f[i]) putchar('A');
else putchar('B');
}
return ;
}
CF 1033 C. Permutation Game的更多相关文章
- CF 1033 D. Divisors
D. Divisors http://codeforces.com/contest/1033/problem/D 题意: 给n个(n<=500)个数,($a_i <= 2 \times 1 ...
- CF 500 B. New Year Permutation 并查集
User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permut ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- [CF 612E]Square Root of Permutation
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, ...
- CF 1141C Polycarp Restores Permutation
Description An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each nu ...
- CF R 209 div 2 CF359B Permutation 构造
LINK:Permutation 休闲一下 开了一道构造题. 看起来毫无头绪 其实仔细观察第二个条件 0<=2k<=n. 容易想到当n是奇数的时候 k的范围更小 再手玩一下第一个条件 容易 ...
- cf B. Levko and Permutation
http://codeforces.com/contest/361/problem/B #include <cstdio> #include <cstring> #includ ...
- cf B. Permutation
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; ...
- 【2019雅礼集训】【CF 960G】【第一类斯特林数】【NTT&多项式】permutation
目录 题意 输入格式 输出格式 思路 代码 题意 找有多少个长度为n的排列,使得从左往右数,有a个元素比之前的所有数字都大,从右往左数,有b个元素比之后的所有数字都大. n<=2*10^5,a, ...
随机推荐
- [原]如何在Android用FFmpeg+SDL2.0之同步音频
同步音频的原理可以参考:http://dranger.com/ffmpeg/tutorial05.html 本文是在 [原]如何在Android用FFmpeg+SDL2.0之同步视频 的基础上面继续 ...
- Windows下设置Ubuntu引导项
最近在进行一些实验环境的配置,最终通过双系统实现了多系统的管理,而不仅限于虚拟机的方式.以此方式成功安装了Windows8.1 Pro和Windows 10,原文在此. 在此基础上进一步安装了 Ubu ...
- 打印出类所在的jar包
ackage time; /** * Created by sheting on 10/20/2017 */ public class Test { public static void main(S ...
- ADF系列-2.EO的高级属性
在上一篇博客 ADF系列-1.EO的各个属性初探 中介绍了EO的一些常用简单属性.本次将介绍EO中一些比较常用的一些高级属性 一.基于Sequence创建EO,一下介绍三种方式(以HR用户的Emplo ...
- [原创] 腾讯RTX二次开发相关的一些注意事项
在企业即时通信方面,腾讯的RTX在国内的占有率应该是很高的 所以,就避免不了要与其他系统进行消息集成 腾讯为此提供了二次开发的工具包,支持JAVA.C#.VB等多种开发语言 但是,目前为止,腾讯官方提 ...
- 一张图解释 implicit
- 给windows添加路由
route add 10.0.0.0 mask 255.0.0.0 172.16.1.253 -p
- SpringBoot 修改仓库
SpringBoot使用aliyun仓库 maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
- 在js中获取到的页面元素为undefined
在学习js的过程中发现了一个问题就是:在js代码中获取页面元素进行操作的时候发现怎么都没有效果,控制台也不报错,弹出获取的元素结果发现是undefined类型. 后来查找了资料发现:因为我的js是写在 ...
- C#中小写人民币转大写
/// <summary> /// 转换成大写人民币 /// </summary> /// <param name="myMoney">< ...