codeforces gym 101889J – Jumping Frog ( 数学+ 思维 好题 )

链接:http://codeforces.com/gym/101889/attachments

思路 :青蛙每次跳长度为len  的距离,如果想要回到原点,那么青蛙跳的点数一定是固定的,把跳过的点标记成红色,那么相邻的两个红点之间的距离也一定是字符串长度n 的因子。那么就问题就可以转化成每次跳长度为两个红点的距离,能否满足题意。那么我就可以直接暴力处理长度n 的所有因子是否可以。因为n的因子不会很多,所以是一个nlogn 的复杂度。

代码:

#include

using namespace std;
typedef long long ll;
const int N =1e5+5;

char s[N];
int vis[N];
int n;

int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);

    for(int len=1;len

 

你可能感兴趣的:(数学,思维)