玉面小蛟龙


私信TA

用户名:2410056091

访问量:14833

签 名:

等  级
排  名 253
经  验 5802
参赛次数 46
文章发表 51
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
int n,k;
int d[100010];
void bfs()
	{
		queue<int> q;
		memset(d,-1,sizeof(d));
		d[0]=0;
		q.push(0);
		while(!q.empty())
			{
				int t=q.front();
				q.pop();
				int a=(t+1)%n;
				if (d[a]==-1)
					{
						d[a]=d[t]+1;
						q.push(a);
					}
				int b=(t+k)%n;
				if (d[b]==-1)
					{
						d[b]=d[t]+1;
						q.push(b);
					}
			}
		return ;
	}
int main()
{
	scanf("%d%d",&n,&k);
	bfs();
	int res=0;
	for(int i=1;i<=n;i++)
		res=max(res,d[i]);
	printf("%d",res);
	return 0;
}
 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区