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;
    }
  • 相关阅读:
    POJ2983Is the Information Reliable
    POJ2706Connect
    POJ1716Integer Intervals
    js Number 转为 百分比
    c# Unicode编码
    json datatable
    分割js 数组
    IQueryable定义一个扩展方法。分页
    sql 计算岁数
    sql 获取一个周的周一和周日
  • 原文地址:https://www.cnblogs.com/war1111/p/7305097.html
Copyright © 2011-2022 走看看