解题思路:
基础深搜
注意事项:
参考代码:
#include"iostream"
#include"cstdio"
#include"queue"
#include"string.h"
using namespace std;
typedef struct{
int dis,num;
}node;
int main(){
int n,k,ans=0;
bool a[1000000];
cin>>n>>k;
memset(a,false,sizeof(a));
queue
node olds;
olds.dis=0,olds.num=0;
Q.push(olds);
a[0]=true;
while(!Q.empty()){
olds=Q.front();
Q.pop();
ans=olds.dis;
int p=olds.num;
int w=(p+1)%n;
if(!a[w]){
a[w]=true;
node news;
news.dis=olds.dis+1,news.num=w;
Q.push(news);
}
w=(p+k)%n;
if(!a[w]){
a[w]=true;
node news;
news.dis=olds.dis+1,news.num=w;
Q.push(news);
}
}
cout<<olds.dis;
return 0;
}
0.0分
2 人评分
C二级辅导-等差数列 (C语言代码)浏览:1213 |
永远的丰碑 (C语言代码)浏览:652 |
蓝桥杯历届试题-九宫重排 (C++代码)浏览:2782 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:958 |
C语言程序设计教程(第三版)课后习题1.6 (C++代码)浏览:889 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:598 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:534 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:653 |
整除问题 (C语言代码)浏览:518 |
简单的a+b (C语言代码)浏览:531 |