Advertisement
mickypinata

PROG-T1167: 1000S Robot

Mar 26th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. typedef struct pos{
  7.     int x;
  8.     int y;
  9. }pos;
  10.  
  11. /// N E S W
  12. pos ctrl[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  13. char cmd[110];
  14. int mov[4];
  15. int len, m, mx;
  16.  
  17. void PrintMove(){
  18.     for(int i = 0; i < 4; ++i){
  19.         cout << mov[i] << " ";
  20.     }
  21.     cout << "\n";
  22.     return;
  23. }
  24.  
  25. int main(){
  26.  
  27.     pos c;
  28.     int tmp;
  29.  
  30.     scanf(" %s", cmd);
  31.     len = strlen(cmd);
  32.     scanf("%d", &m);
  33.  
  34.     for(int i = 0; i < len; ++i){
  35.         switch(cmd[i]){
  36.         case 'N':
  37.             ++mov[0];
  38.             break;
  39.         case 'E':
  40.             ++mov[1];
  41.             break;
  42.         case 'S':
  43.             ++mov[2];
  44.             break;
  45.         case 'W':
  46.             ++mov[3];
  47.             break;
  48.         }
  49.     }
  50.  
  51.     mx = 0;
  52.     for(int n = 0; n <= m; ++n){
  53.         if(mov[0] - n >= 0){
  54.             for(int e = 0; e <= m - n; ++e){
  55.                 if(mov[1] - e >= 0){
  56.                     for(int s = 0; s <= m - n - e; ++s){
  57.                         if(mov[2] - s >= 0 && mov[3] - m + n + e + s >= 0){
  58.                             c = {0, 0};
  59.                             c.x += ctrl[0].x * (mov[0] - n);
  60.                             c.y += ctrl[0].y * (mov[0] - n);
  61.                             c.x += ctrl[1].x * (mov[1] - e);
  62.                             c.y += ctrl[1].y * (mov[1] - e);
  63.                             c.x += ctrl[2].x * (mov[2] - s);
  64.                             c.y += ctrl[2].y * (mov[2] - s);
  65.                             c.x += ctrl[3].x * (mov[3] - m + n + e + s);
  66.                             c.y += ctrl[3].y * (mov[3] - m + n + e + s);
  67.                             tmp = abs(c.x) + abs(c.y);
  68.                             mx = max(mx, tmp);
  69.                         }
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.     }
  75.     cout << 2 * mx;
  76.  
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement