优雅的伊利


私信TA

用户名:995745

访问量:4993

签 名:

等  级
排  名 1694
经  验 2598
参赛次数 6
文章发表 5
年  龄 0
在职情况 学生
学  校 烟台大学
专  业

  自我简介:

解题思路:
基础深搜
注意事项:

参考代码:

#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 人评分

  评论区