zoukankan      html  css  js  c++  java
  • 好奇怪的游戏

    洛谷P1747 好奇怪的游戏

    马走日翻版,注意方向不要打错,还有就是题目要求最小,要加min

    #include<bits/stdc++.h>
    using namespace std;
    
    int x[]={-2,-2,-1,-1,-2,-2, 1, 2, 2,2,2,1};
    int y[]={-1,-2,-2, 2, 2, 1,-2,-2,-1,1,2,2};
    
    queue<int>q1;
    queue<int>q2;
    
    int xi,yi,xj,yj;
    int o=true,k=true;
    int a[100][100];
    int ans=999999999;
    int an=999999999;
    
    
    int main()
    {
        cin>>xi>>yi>>xj>>yj;
        int t=0;
        q1.push(1),q2.push(1);
        while(!q1.empty()&&(o||k))
        {
            int xx=q1.front();
            int yy=q2.front();
            for(int i=0;i<12;i++)
            {
                if(yy+y[i]>0&&xx+x[i]>0&&xx+x[i]<100&&yy+y[i]<100&&((a[xx+x[i]][yy+y[i]]>a[xx][yy]+1)||(a[xx+x[i]][yy+y[i]]==0)))
                {
                    a[xx+x[i]][yy+y[i]]=a[xx][yy]+1;
                    if(xx+x[i]==xi&&yy+y[i]==yi&&o)
                    {
                    //    cout<<a[xx][yy]+1<<endl;
                        ans=min(ans,a[xx+x[i]][yy+y[i]]);
                        o=false;
                    }
                    if(xx+x[i]==xj&&yy+y[i]==yj&&k)
                    {
                    //    cout<<a[xx][yy]+1<<endl;
                        an=min(an,a[xx+x[i]][yy+y[i]]);
                        k=false;
                    }
                    q1.push(xx+x[i]);
                    q2.push(yy+y[i]);
                }
            }
            q1.pop();
            q2.pop();
        }
        cout<<ans<<endl;
        cout<<an<<endl;
        return 0;
    }
  • 相关阅读:
    fastjson-alibaba
    ubuntu 入门
    资料文档
    asp.net mvc View视图相关
    视频
    js第三方
    工具类网址
    [转]初学者的编程自学指南
    seajs的使用--主要了解模块化
    其它
  • 原文地址:https://www.cnblogs.com/war1111/p/7305097.html
Copyright © 2011-2022 走看看