//Date: //Skill: //Bug: /Definations/ //循环控制 #define CLR(a) memset((a),0,sizeof(a)) #define RE(i,n) for(int i=0;i<int(n);i++) #define RE2(i,n) for(int i=1;i<=int(n);i++) #define FOR(x,vec) for(vector<int>::iterator it=vec.begin();it!=vec.end();++it) { int &x(*it); //输入输出 //#define INC(c) do{scanf("%c",&c);}while(isspace(c)) //#define ON cout<<endl #define PII pair<int,int> using namespace std; const int inf = 0x3f3f3f3f; const long long llinf = 0x3f3f3f3f3f3f3f3f; Options// typedef long long ll; #define stdcpph #define CPP_IO #ifdef stdcpph #include<bits/stdc++.h> #else #include<ctype.h> #include<string.h> #include<math.h> #include<vector> #include<map> #include<algorithm> #include<functional> #ifdef CPP_IO #include<iostream> #include<iomanip> #include<string> #else #include<stdio.h> #endif #endif Basic Functions// template<typename INint> inline void IN(INint &x) { x = 0; int f = 1; char c; cin.get(c); while (c<'0' || c>'9') { if (c == '-')f = -1; cin.get(c); } while (c >= '0'&&c <= '9') { x = x * 10 + c - '0'; cin.get(c); } x *= f; } template<typename INint> inline void OUT(INint x) { if (x > 9)OUT(x / 10); cout.put(x % 10 + '0'); } Added Functions// const int maxn = int(1e5 + 5); ll offx[maxn] = { 0 }, offy[maxn] = { 0 }; ll n; ll x, y; string mod = "UDLR"; ll ox[] = { 0,0,-1,1 }, oy[] = { 1,-1,0,0 }; bool can(ll num) { ll cir = num / n, res = num % n; ll dx = cir * offx[n] + offx[res] , dy = cir * offy[n] + offy[res]; return (abs(dx - x) + abs(dy - y)) <= num; } Code/ int main() { //freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin); int T(1), times(0); #ifdef CPP_IO// CPP_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //cin >> T; #else //IN(T); #endif / while (++times, T--) { { ll a, b, c, d; cin >> a >> b >> c >> d; x = c - a; y = d - b; } cin >> n; RE2(i,n) { char c; cin >> c; ll in = find(mod.begin(), mod.end(), c) - mod.begin(); offx[i] = offx[i - 1] + ox[in]; offy[i] = offy[i - 1] + oy[in]; } ll le(-1), ri(1ll*inf*inf); while (le + 1 != ri) { ll mid = ((le + ri) >> 1); if (can(mid))ri = mid; else le = mid; } if (ri == 1ll*inf*inf)ri = -1; cout << ri << endl; } / return 0; }