P8674题解
Nuyoah_awa · · 题解
题目分析
小明有一块电子表,准备调时间,M78 星云上一个小时
题目分析
小明从第
我们可以把这道题视为一个图论题,我们将每个数
由于每个点到
code
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int N = 1e5 + 5;
int n, k, t[N], cnt[N], x, y1, y2, ans;
queue <int> q;
int main()
{
scanf("%d %d", &n, &k);
cnt[0] = true;
q.push(0);
while(!q.empty())
{
x = q.front();
q.pop();
ans = max(ans, t[x]);
y1 = (x + k) % n, y2 = (x + 1) % n;
if(!cnt[y1])
{
t[y1] = t[x] + 1, cnt[y1] = true;
q.push(y1);
}
if(!cnt[y2])
{
t[y2] = t[x] + 1, cnt[y2] = true;
q.push(y2);
}
}
printf("%d", ans);
return 0;
}