现在的位置: 首页 > 综合 > 正文

Floyd判圈算法(龟兔赛跑算法)

2018年03月17日 ⁄ 综合 ⁄ 共 339字 ⁄ 字号 评论关闭

今天通过接触到了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);
}

 

抱歉!评论已关闭.