Advertisement
hasib_mo

Untitled

Jul 4th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6.  
  7. #include<algorithm>
  8. #include<vector>
  9. #include<queue>
  10. #include<stack>
  11. #include<map>
  12. #include<utility>
  13. #include<set>
  14.  
  15.  
  16. #define FOR(i, s, e) for(int i=s; i<e; i++)
  17. #define loop(i, n) FOR(i, 0, n)
  18. #define sf scanf
  19. #define pf printf
  20. #define pb push_back
  21. #define MP make_pair
  22. #define fr first
  23. #define sc second
  24. #define ll long long
  25. #define dd double
  26. #define all(v) v.begin(), v.end()
  27. #define PI acos(-1.0)
  28. #define mem(ara, value) memset(ara, value, sizeof(ara))
  29. #define paii pair<int, int>
  30. #define pall pair<ll, ll>
  31. #define SZ(a) int(a.size())
  32. #define read(nm) freopen(nm, "r", stdin)
  33. #define write(nm) freopen(nm, "w", stdout)
  34. #define dump(x) cout<<#x<<" = "<<x<<endl
  35.  
  36. using namespace std;
  37.  
  38. #define take(args...) asdf,args
  39. #define debug(args...) asdfg,args; cout<<endl
  40. struct ASDF{
  41.     ASDF& operator,(int &a) {
  42.         sf("%d", &a);
  43.         return *this;
  44.     }
  45.     ASDF& operator,(long int &a){
  46.         sf("%ld", &a);
  47.         return *this;
  48.     }
  49.     ASDF& operator,(long long int &a){
  50.         sf("%lld", &a);
  51.         return *this;
  52.     }
  53.     ASDF& operator,(char &c){
  54.         sf("%c", &c);
  55.         return *this;
  56.     }
  57.     ASDF& operator,(double &d){
  58.         sf("%lf", &d);
  59.         return *this;
  60.     }
  61.  
  62.     template<typename T>
  63.     ASDF& operator,(T &a){
  64.         cin>>a;
  65.         return *this;
  66.     }
  67. }asdf;
  68. struct ASDFG{
  69.     template<typename T>
  70.     ASDFG& operator,(vector<T> &v){
  71.         pf("[");
  72.         cout<<v[0];
  73.         FOR(i, 1, SZ(v)){
  74.             cout<<", "<<v[i];
  75.         }
  76.         pf("]");
  77.         return *this;
  78.     }
  79.  
  80.     template<typename T>
  81.     ASDFG& operator,(T x) {
  82.         cout<<x<<" ";
  83.         return *this;
  84.     }
  85.  
  86.  
  87. }asdfg;
  88.  
  89.  
  90.  
  91. //Header ends here
  92.  
  93. ostream &operator<<(ostream &os, paii s)
  94. {
  95.     cout<<"(" <<s.fr<<", "<<s.sc<<")";
  96.     return os;
  97. }
  98.  
  99. int main()
  100. {
  101.     paii lastPos;
  102.     string str;
  103.  
  104.     take(lastPos.fr, lastPos.sc, str);
  105.  
  106.     paii currentPos;
  107.     currentPos.fr = 0;
  108.     currentPos.sc = 0;
  109.  
  110.     vector<paii>allPos;
  111.     allPos.pb(currentPos);
  112.     loop(i, SZ(str))
  113.     {
  114.         switch(str[i])
  115.         {
  116.             case 'U':
  117.                 currentPos.sc++;
  118.                 break;
  119.             case 'D':
  120.                 currentPos.sc--;
  121.                 break;
  122.             case 'L':
  123.                 currentPos.fr--;
  124.                 break;
  125.             case 'R':
  126.                 currentPos.fr++;
  127.                 break;
  128.  
  129.         }
  130.         //cout<<currentPos<<str[i];
  131.         allPos.pb(currentPos);
  132.     }
  133.  
  134.     //debug(currentPos);
  135.  
  136.  
  137.     bool ifPossible = false;
  138.  
  139.     paii diff = currentPos;
  140.     int n;
  141.     loop(i, SZ(allPos))
  142.     {
  143.         currentPos = allPos[i];
  144.  
  145.  
  146.         if(diff.fr == 0 && diff.sc == 0)
  147.         {
  148.             if(lastPos.fr == currentPos.fr && lastPos.sc == currentPos.sc)
  149.             {
  150.                 ifPossible = 1;
  151.                 break;
  152.             }
  153.         }
  154.         else if(diff.fr == 0)
  155.         {
  156.             if(lastPos.fr == currentPos.fr &&(lastPos.sc - currentPos.sc)%diff.sc == 0 && (lastPos.sc - currentPos.sc)/diff.sc >-1)
  157.             {
  158.                 ifPossible = 1;
  159.                 break;
  160.             }
  161.         }
  162.         else if(diff.sc == 0)
  163.         {
  164.             if(lastPos.sc == currentPos.sc && (lastPos.fr - currentPos.fr)%diff.fr == 0 && (lastPos.fr - currentPos.fr)/diff.fr > -1)
  165.             {
  166.                 ifPossible = 1;
  167.                 break;
  168.             }
  169.         }
  170.         else
  171.         {
  172.             if((lastPos.fr - currentPos.fr)%diff.fr == 0)
  173.             {
  174.                 n = (lastPos.fr - currentPos.fr)/diff.fr;
  175.                 if(n > -1 && n*diff.sc + currentPos.sc == lastPos.sc)
  176.                 {
  177.                     ifPossible = 1;
  178.                     break;
  179.                 }
  180.             }
  181.         }
  182.  
  183.  
  184.  
  185.     }
  186.  
  187.     //debug(allPos);
  188.  
  189.     if(ifPossible)cout<<"Yes";
  190.     else cout<<"No";
  191.  
  192.     return 0;
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement