zoukankan      html  css  js  c++  java
  • poj2369

    简单题

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 1005

    int f[maxn];
    int n;
    bool vis[maxn];

    int gcd(int x, int y)
    {
    if (!x || !y)
    return x > y ? x : y;
    for (int t; t = x %y; x = y, y = t);
    return y;
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 0; i< n; i++)
    {
    int a;
    scanf(
    "%d", &a);
    a
    --;
    f[a]
    = i;
    }
    memset(vis,
    0, sizeof(vis));
    int ans = 1;
    for (int i = 0; i < n; i++)
    if (!vis[i])
    {
    int a = i;
    int b = 0;
    while (!vis[a])
    {
    vis[a]
    = true;
    a
    = f[a];
    b
    ++;
    }
    ans
    = ans / gcd(ans, b) * b;
    }
    printf(
    "%d\n", ans);
    return 0;
    }
  • 相关阅读:
    12月4日
    12月3日
    12月2日
    12月1日
    11月30日
    11月29日
    11月28日
    11月27日
    jquery mobile-按钮控件
    ap web
  • 原文地址:https://www.cnblogs.com/rainydays/p/2114585.html
Copyright © 2011-2022 走看看