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, ...
随机推荐
- Linux汉化(Cent Os汉化)
在腾讯云上购买了Cent Os7.1的云服务器,是英文版啊,有没有?对于我这种英文的渣渣啊,所以我要用中文版,我就是这么low,怎么着呢? Ok ,在汉化之前,先查看系统的语言环境, echo $LA ...
- What Is a Computer System?
What Is a Computer System? A combination of Five or Six Elements The term computer is used to descri ...
- MATLAB入门学习(六)
今天学三维作图 (*^__^*)…… 三维曲线作图 用到的命令:plot3 基本格式:plot3(x,y,z,s) 这里要画曲线,你需要知道该曲线的参数方程x=x(t),y=y(t),z=z(t) 然 ...
- 6.spring:AOP(注解)
spring Aop AOP面向切面编程,与OOP面向对象编程相辅相成 AOP中最基本的单元是切面 问题: 代码混乱:越来越多的业务需求(日志&验证)加入后,原有的业务方法急剧膨胀,每个方法 ...
- Linux磁盘分区,挂载
分区基础知识 分区的方式: 1) mbr分区: 1.最多支持四个主分区 2.系统只能安装在主分区 3.扩展分区要占一个主分区 4.MBR最大只支持2TB,但拥有最好 ...
- Qgis里的查询过滤
查询过虑实现方式 通过给getFeatures()传递 QgsFeatureRequest对象,实现数据的过虑,下边是一个查询的例子: request = QgsFeatureRequest() re ...
- JavaScript读取本地json文件
JavaScript读取本地json文件 今天调试了一上午,通过jQuery读取本地json文件总是失败,始终找不出原因,各种方法都试了 开始总以为是不是json格式的问题.高了半天不行 后来读了一个 ...
- SpringMVC使用校验validator校验对象属性
1.pom.xm添加依赖 <dependency> <groupId>javax.validation</groupId> <artifactId>va ...
- java基本方法
Java 方法 在前面几个章节中我们经常使用到 System.out.println(),那么它是什么呢? println() 是一个方法. System 是系统类. out 是标准输出对象. 这句话 ...
- maven 环境变量 设置
Maven安装与配置 一.需要准备的东西 1. JDK 2. Eclipse 3. Maven程序包 二.下载与安装 1. 前往https://maven.apache.org/download. ...