zoukankan      html  css  js  c++  java
  • AtCoder

    题意

    https://vjudge.net/problem/AtCoder-2282

    告诉你sx,sy,tx,ty,问从s走到t,再从t走到s,再从s走到t,再从t回到s的最短路,每次只能上下左右选一个走1,除了s和t,其他点只能走一次。

    思路

    这是个沙雕构造题,我画出来了却没看出来。。太沙雕了。

    借用别人的图:

     然后乱走即可。。

    代码

    #include <bits/stdc++.h>
    
    using namespace std;
    #define ll long long
    const int N=1e3+5;
    const int mod=1e9+7;
    int main()
    {
        ios::sync_with_stdio(false);
        int sx,sy,tx,ty;
        cin>>sx>>sy>>tx>>ty;
        cout<<"D";
        for(int i=0; i<tx-sx+1; i++)
            cout<<"R";
        for(int i=0; i<ty-sy+1; i++)
            cout<<"U";
        for(int i=0; i<tx-sx+1; i++)
            cout<<"L";
        for(int i=0; i<ty-sy; i++)
            cout<<"D";
        for(int i=0; i<tx-sx; i++)
            cout<<"R";
        for(int i=0; i<ty-sy+1; i++)
            cout<<"U";
        for(int i=0; i<tx-sx+1; i++)
            cout<<"L";
        for(int i=0; i<ty-sy+1; i++)
            cout<<"D";
        cout<<"R"<<endl;
        return 0;
    }
    //1 2 4 8 16 30 60 96
    

      

  • 相关阅读:
    最小生成树算法
    并查集
    背包问题
    木桶排序
    STL之vector
    STL中的queue用法与stack用法对比
    快速幂求模
    归并排序+典型例题(逆序对)
    负进制转换
    冒泡排序
  • 原文地址:https://www.cnblogs.com/mcq1999/p/11843388.html
Copyright © 2011-2022 走看看