今天通过接触到了Floyd判圈算法,觉得这个算法很神奇,在网上找了N久的算法资料,终于让我找到了。
传送门:http://blog.csdn.net/thestoryofsnow/article/details/6822576
有时间再去学习学习。
示例代码:
void solve() { read_case(); int ans = k; int count = 0; int k1 = k, k2 = k; do { k1 = next(n, k1); k2 = next(n, k2); if(k2 > ans) ans = k2; k2 = next(n, k2); if(k2 > ans) ans = k2; //count++; //算出循环节 }while(k1 != k2); printf("%d\n", ans); //printf("%d\n", count); }