Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int x, y, n, xl, yl, out;
  5. pair <long long, long long> bg, en;
  6. string s;
  7. vector <pair <int, int>> wind;
  8.  
  9. int main(){
  10.     freopen("in.data", "r", stdin);
  11.     cin >> bg.first >> bg.second >> en.first >> en.second >> n >> s;
  12.    
  13.     wind.push_back(make_pair(0, 0));
  14.  
  15.     x = bg.first - en.first;
  16.     y = bg.second - en.second;
  17.  
  18.     for(int i = 1; i <= n; i++){
  19.         if(s[i-1] == 'U')
  20.             yl++;
  21.         if(s[i-1] == 'D')
  22.             yl--;
  23.         if(s[i-1] == 'R')
  24.             xl++;
  25.         if(s[i-1] == 'L')
  26.             xl--;
  27.         wind.push_back(make_pair(xl, yl));
  28.         //cout <<  xl << " " << wind[i].first << " " << abs(x + wind[i].first) << " ||||||||| " <<  abs(y + wind[i].second) << endl;
  29.         if(abs(x + wind[i].first) + abs(y + wind[i].second) <= n){
  30.             cout << n;
  31.             return 0;
  32.         }
  33.     }
  34.  
  35.     //cout << abs(x + wind[n].first) + abs(y + wind[n].second) << " " << n + abs(y) + abs(x) << endl;
  36.     if(abs(x + wind[n].first) + abs(y + wind[n].second) >= n + abs(y) + abs(x)){
  37.         cout << -1;
  38.         return 0;
  39.     }
  40.  
  41.     out = (abs(x) + abs(y))  / (abs(x) - abs(x + wind[n].first) + abs(y) - abs(y + wind[n].second))  - 1;
  42.     x+= out*wind[n].first;
  43.     y+= out*wind[n].second;
  44.  
  45.     for(int i = 1; i <= n; i++){
  46.         if(abs(x + wind[i].first) + abs(y + wind[i].second) <= i + n * out){
  47.             cout << n*out + i;
  48.             return 0;
  49.         }
  50.     }
  51.  
  52.     //for()
  53.  
  54. return 0;  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement