zoukankan      html  css  js  c++  java
  • Codeforces 542C

      尽管在下面的一部分解题的方法都有问题...

      但是每一次重新提交都是打了一个有意义的补丁的呢

      可见在我做题的过程中有多少问题存在...

      现在想想,类似于是变量没有开int64,过程函数忘开int64..还有就是中间的很多问题


      

    C. Idempotent functions

    Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function , that for any  the formula g(g(x)) = g(x) holds.

    Let's denote as f(k)(x) the function f applied k times to the value x. More formally, f(1)(x) = f(x), f(k)(x) = f(f(k - 1)(x)) for each k > 1.

    You are given some function . Your task is to find minimum positive integer k such that functionf(k)(x) is idempotent.

    Input

    In the first line of the input there is a single integer n (1 ≤ n ≤ 200) — the size of function f domain.

    In the second line follow f(1), f(2), ..., f(n) (1 ≤ f(i) ≤ n for each 1 ≤ i ≤ n), the values of a function.

      直接开始说好了...刚开始忽略了数据范围,用了倍增...然后衍生出一系列奇奇怪怪的问题

      首先考虑数据中存在环的情况,那么答案为了满足这些数的需求需要满足整除所有环的大小

      然后对于其他的数,再另外考虑

      刚开始忽略了数据范围,用了二分...然后最后发现好像是不满足单调性的...

      刚开始觉得只要不在环中一定就是朝着某个方向一点点贴近

      但是发现忘记考虑了这种情况

      这样的话其实从小到大枚举答案就可以啦...

      最后发现订正的全过程无非是两个阶段:

      1)将O(logn)的倍增改成O(n)的模拟

      2)将O(logn)的二分答案改成O(n)的枚举答案

      然后就过了...

      以后再也不能鄙视数据范围了..

      04./May

  • 相关阅读:
    最大相邻差值 数学 桶排序
    hdu-1536 S-Nim SG函数
    博弈论初步(SG函数)
    hdu-5009 Paint Pearls DP+双向链表 with Map实现去重优化
    hdu-5015 233 Matrix 矩阵快速幂
    hdu-1430 魔板 康拓展开+映射优化
    hdu-1043 bfs+康拓展开hash
    康拓展开-排列的hash
    Daily Scrum 12.23
    Daily Scrum 12.22
  • 原文地址:https://www.cnblogs.com/mjy0724/p/4476994.html
Copyright © 2011-2022 走看看