ICPC Latin American Regional – 2017 Jumping Frog

Pog the Frog wants to compete in the World Frog Jump competition, which will take place in Nlogonia.
In the competition, each frog must perform a sequence of acrobatic jumps in a specially built arena. The
arena is composed of N equally spaced positions around a circumference (the arc between two adjacent
positions is always the same length) where each position can be either a rock or a pond. The positions
are numbered sequentially from 0 to N − 1 in the clockwise direction, so that judges can easily make
notes about which jumps were performed in each position. Thus, position 0 is adjacent to positions 1
and N − 1 in the arena.
The competition rules stipulate that the sequence of jumps of each frog must start at a rock, always
go from a rock to another rock, and finish at the same position it started. The rules do not require frogs
to use every rock in the arena for their sequence of jumps.
Pog the Frog is currently practicing for the competition. He must develop two skills. First, he needs
to get better at jumping from one rock to another, since landing on either a pond or outside of the
marked positions can mean disqualification. Besides that, he must learn impressing acrobatic moves.
With that in mind, he has decided on a practicing strategy. In the beginning of each practice session,
Pog the Frog will pick a starting rock and an integer jump length K between 1 and N − 1. After that,
whenever he is standing on a rock numbered i, he will aim his next acrobatic jump at the rock whose
number is obtained by getting the remainder of the division of i + K by N. He will stop when he lands
on the starting rock. For example, if the arena has 3 positions, all of them rocks, and Pog the Frog
starts at position 0 and picks K = 2, he will first jump from rock 0 to rock 2, then to rock 1, and finally
jump back to rock 0. At this point, his practice session ends.
Given the description of the N positions in the arena, help Pog the Frog by answering this question:
how many distinct values of K can he choose for his practice sessions, if he can use any rock as a starting
position for his sequence of jumps?
Input
The input consists of a single line that contains a string S of N characters (3 ≤ N ≤ 105
), representing
the positions in the arena. The i-th character of S (i = 0, 1, . . . , N − 1) indicates that the
position i in the arena is either a rock (uppercase letter “R”) or a pond (uppercase letter “P”).
Output
Output a single line with an integer representing the number of distinct jump lengths that Pog the
Frog can choose for his practice sessions, given that he can use any rock as a starting position for his
sequence of jumps.
Sample input 1
RRR
Sample output 1
2
Sample input 2
RRPR
Sample output 2
1
Sample input 3
PRP
Sample output 3
0

题意:

给你一个字符串,从一个点开始跳,最终跳到原点,不经过P的点,有多少种情况。

题解:

跳环的时候,若这个环有n个数,每次跳k步步和每次跳gcd(k,n)步是一样的,这个可以很容易被证明。那么我们就可以枚举n的所有因子,然后枚举每一个点为开头的情况,如果这个点是p的话,那么以j%i为开头的情况就不可行了。

#include
using namespace std;
const int N=1e5+5;
int num[N],vis[N];
char s[N];
int main()
{
    scanf("%s",s);
    int n=strlen(s);
    for(int i=1;i

你可能感兴趣的:(想法,数学)