C. Permutation Game
Http://codeforces.com/contest/1033/problem/C
Test instructions
A permutation, each position I go to the position J satisfies: A[j]>a[i], (j-i) is a multiple of a[i]. Ask if there is a winning strategy starting at each location.
Analysis:
Game theory + topology.
Since it is an arrangement, you can enumerate each number and determine if a of this position is greater than it, if you can connect the edge. The complexity of this is $nlogn$.
Then for some no way to go to the point, this is a must-lose, according to the definition of winning and must fail: the successor State of the winning states there is at least one must fail state, the subsequent state of the failure will be all the winning state.
Then build the inverse diagram on the DAG topology.
Code:
1#include <cstdio>2#include <algorithm>3#include <cstring>4#include <cmath>5#include <iostream>6#include <cctype>7#include <Set>8#include <vector>9#include <queue>Ten#include <map> One #defineFi (s) freopen (S, "R", stdin); A #defineFo (s) freopen (S, "w", stdout); - using namespacestd; -typedefLong LongLL; the -InlineintRead () { - intx=0, f=1;CharCh=getchar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; - for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0';returnx*F; + } - + A Const intN =1000005; at intA[n], deg[n], q[n], f[n]; -vector<int>T[n]; - - intMain () { - intn =read (); - for(intI=1; i<=n; ++i) A[i] =read (); in - for(intI=1; i<=n; ++i) { to for(intJ=i+a[i]; j<=n; j+=A[i]) + if(A[j] > A[i]) T[j].push_back (i), deg[i] + +; - for(intJ=i-a[i]; j>=1; j-=A[i]) the if(A[j] > A[i]) T[j].push_back (i), deg[i] + +; * } $ Panax Notoginseng intL =1, R =0; -Memset (F,-1,sizeof(f)); the for(intI=1; i<=n; ++i) + if(!deg[i]) q[++r] = i, f[i] =0; A the while(L <=R) { + intU = q[l + +]; - for(intSz=t[u].size (), i=0; i<sz; ++i) { $ intv =T[u][i]; $ if(F[v] = =-1) { - if(F[u] = =0) F[v] =1; - ElseF[V] =0; the } - Else {Wuyi if(F[u] = =0) F[v] =1; the } -DEG[V]--; Wu if(!deg[v]) q[++r] =v; - } About } $ for(intI=1; i<=n; ++i) { - if(F[i]) Putchar ('A'); - ElsePutchar ('B'); - } A return 0; +}
CF 1033 C. Permutation Game