zoukankan      html  css  js  c++  java
  • [POJ

    还是很简单的水题。不过他的边界条件我到现在还是不是很懂hhhh

    #include <cstdio>
    #include <queue>
    #include <cstring>
    
    using namespace std;
    
    struct position
    {
        int x;
        int min;
    };
    
    queue <position> q;
    int vis[100001];
    int main()
    {
        position man, temp;
        int start, end;
        while(~scanf("%d%d", &start, &end))
        {
        
        memset(vis, 0, sizeof(vis));
        while(!q.empty())
            q.pop();
        
        man.x = start;
        man.min = 0;
        q.push(man);
        vis[man.x]=1;
        while(!q.empty())
        {
            man = q.front();
            q.pop();
                if(man.x == end)
                    {
                        printf("%d
    ", man.min);
                        break;    
                    }
            temp.x = man.x+1;
            if(temp.x>=0 && temp.x<=100000 && !vis[temp.x])
                {
                    temp.min = man.min +1;
                    vis[temp.x] =1 ;
                    q.push(temp);
                }
            
            
            temp.x = man.x-1;
            if(temp.x>=0 && temp.x<=100000 && !vis[temp.x])
                {
                    temp.min = man.min +1;
                    vis[temp.x] =1 ;
                    q.push(temp);
                }
                
            temp.x = man.x*2;
            if(temp.x>=0 && temp.x<=100000 && !vis[temp.x])
                {
                    temp.min = man.min +1;
                    vis[temp.x] =1 ;
                    q.push(temp);
                }
            
        }
    }
        
        
        return 0;
    }
  • 相关阅读:
    Python 爬虫一 简介
    linux 基础笔记本
    Celery 分布式任务队列快速入门
    Git & Github
    Python 设计模式
    Python 数据结构
    Python 基础算法
    js2wordcloud 词云包的使用
    lambda 3
    sql server 远程
  • 原文地址:https://www.cnblogs.com/Vikyanite/p/11382478.html
Copyright © 2011-2022 走看看