码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 542C - 漫长艰辛的解题历程

时间:2015-05-04 20:10:18      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

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

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

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

  现在想想,类似于是变量没有开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

Codeforces 542C - 漫长艰辛的解题历程

标签:

原文地址:http://www.cnblogs.com/mjy0724/p/4476994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!