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的更多相关文章

  1. CF 1033 D. Divisors

    D. Divisors http://codeforces.com/contest/1033/problem/D 题意: 给n个(n<=500)个数,($a_i <= 2 \times 1 ...

  2. 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 ...

  3. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  4. [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, ...

  5. CF 1141C Polycarp Restores Permutation

    Description An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each nu ...

  6. CF R 209 div 2 CF359B Permutation 构造

    LINK:Permutation 休闲一下 开了一道构造题. 看起来毫无头绪 其实仔细观察第二个条件 0<=2k<=n. 容易想到当n是奇数的时候 k的范围更小 再手玩一下第一个条件 容易 ...

  7. cf B. Levko and Permutation

    http://codeforces.com/contest/361/problem/B #include <cstdio> #include <cstring> #includ ...

  8. cf B. Permutation

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; ...

  9. 【2019雅礼集训】【CF 960G】【第一类斯特林数】【NTT&多项式】permutation

    目录 题意 输入格式 输出格式 思路 代码 题意 找有多少个长度为n的排列,使得从左往右数,有a个元素比之前的所有数字都大,从右往左数,有b个元素比之后的所有数字都大. n<=2*10^5,a, ...

随机推荐

  1. Perl入门(七) Perl脚本的调试

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/sunshoupo211/article/details/32711165 编程中错误不可避免.调试可 ...

  2. UVA12034 Race

    嘟嘟嘟 令dp[i]表示在n个人中,有 i 个人获得第一名的方案数,转移方程为dp[i] = C(i, n) * dp[n - i].C(i, n)就是从n个人中选 i 个第一,那么剩下的n - i ...

  3. C#使用DotNetZip对zip压缩包进行添加删除操作

    参考:http://stackoverflow.com/questions/9855155/how-can-i-delete-a-directory-in-a-zip-file-using-net D ...

  4. 【luogu P2195 HXY造公园】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2195 fir.吐槽题目(省略1w字 sec.考虑对一个森林的维护,每棵树用并查集维护. 操作1:输出当前查询 ...

  5. Mahout介绍

    3.11简介 Mahout:是一个Apache的一个开源的机器学习库,主要实现了三大类算法Recommender (collaborative filtering).Clustering.classi ...

  6. sharePoint中简单的父页面跳转子页面代码!

    1,SharePoint中挺简单的一个父页面跳转到子页面的Js代码!常常用到,每次都到以前的项目中去找代码,挺麻烦! (1)父页面代码. function imgAddParentclick() { ...

  7. easy-im:一款基于netty的即时通讯系统

    介绍 easy-im是面向开发者的一款轻量级.开箱即用的即时通讯系统,帮助开发者快速搭建消息推送等功能. 基于easy-im,你可以快速实现以下功能: + 聊天软件 + IoT消息推送 基本用法 项目 ...

  8. SQL 二

    1.执行DML语句的步骤:在数据库缓冲区缓存中搜索相关的块:将块从数据文件复制到缓冲区:将变更向量写入日志缓冲区:将变更向量应用于数据库缓冲区缓存.2.重做可以保护的段类型:索引段.表段.撤销段.3. ...

  9. CentOS7 使用chrony搭建集群中的时间同步服务

    一.集群环境: 系统:CentOS7-minimal 集群中的两台主机ip:10.132.226.103/24  10.132.226.104/24 二.CentOS7中时间相关命令timedatec ...

  10. 利用mysqlbinlog_flashback闪回丢失数据

            today,i'll have a test with the open source tool mysqlbinlog_flashback which is released by ...