題意
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/127179.html
標籤:其他
