Advertisement
juanjo12x

UVA_10901_Ferry_Loading_III

Aug 15th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #include <sstream>
  14. #include <stdlib.h>
  15. #include <cmath>
  16. #define FOR(i,A) for(typeof (A).begin() i = (A).begin() ; i != (A).end() ; i++)
  17. #define debug( x ) cout << #x << " = " << x << endl
  18. #define clr(v,x) memset( v, x , sizeof v )
  19. #define all(x) (x).begin() , (x).end()
  20. #define rall(x) (x).rbegin() , (x).rend()
  21. #define TAM 110
  22.  
  23. using namespace std;
  24.  
  25. typedef pair<int,int> ii ;
  26. typedef long long ll ;
  27. typedef long double ld ;
  28. typedef pair<int,ii> pii ;
  29.  
  30. int main() {
  31.  int c, n, t, m, val, kr = 0, kl = 0, cap = 0, time = 0, cont = 0;
  32.  char direccion[20];
  33.  scanf("%d", &c);
  34.  for (int k = 0; k < c; k++) {
  35.   queue<int> left, right;
  36.   scanf("%d %d %d", &n, &t, &m);
  37.   kr = kl = 0;
  38.   vector<int> posiciones(m);
  39.   cont = 0;
  40.   for (int i = 0; i < m; i++) {
  41.    scanf("%d %s", &val, direccion);
  42.    if(strcmp(direccion,"left") == 0)
  43.     left.push(val), kl++,posiciones[cont++] = 0;
  44.    else
  45.     right.push(val), kr++,posiciones[cont++] = 1;
  46.   }
  47.   vector<int> listaL(kl), listaR(kr);
  48.   kl = kr = cap = time = 0;
  49.   string ini = "left";
  50.   while (!left.empty() || !right.empty()) {
  51.    if (!left.empty() && !right.empty()) {
  52.     if(left.front() > time && right.front() > time) {
  53.      if(left.front() > right.front()) {
  54.       time += right.front() - time;
  55.       if(ini == "left") time += t;
  56.       ini = "right";
  57.      }
  58.      else {
  59.       time += left.front() - time;
  60.       if(ini == "right") time += t;
  61.       ini = "left";
  62.      }
  63.     }
  64.    }
  65.    else {
  66.     if (left.empty()) {
  67.      if (right.front() > time) {
  68.       time += right.front() - time;
  69.       if(ini == "left") time += t;
  70.       ini = "right";
  71.      }
  72.     }
  73.     else {
  74.      if (left.front() > time) {
  75.       time += left.front() - time;
  76.       if(ini == "right") time += t;
  77.       ini = "left";
  78.      }
  79.     }
  80.    }
  81.    if (ini == "left") {
  82.     cap = 0;
  83.     while (cap < n && !left.empty() && left.front() <= time) {
  84.      //printf("left %d\n", time + t);
  85.      listaL[kl++] = time + t;
  86.      left.pop();
  87.      cap++;
  88.     }
  89.     time += t;
  90.     ini = "right";
  91.    }
  92.    else {
  93.     cap = 0;
  94.     while (cap < n && !right.empty() && right.front() <= time) {
  95.      //printf("right %d\n", time + t);
  96.      listaR[kr++] = time + t;
  97.      right.pop();
  98.      cap++;
  99.     }
  100.     time += t;
  101.     ini = "left";
  102.    }
  103.   }
  104.   kl = kr = 0;
  105.   for (int i = 0; i < m; i++) {
  106.    if (!posiciones[i])
  107.     printf("%d\n", listaL[kl++]);
  108.    else
  109.     printf("%d\n", listaR[kr++]);
  110.   }
  111.   if(k + 1 != c) printf("\n");
  112.  }
  113.  return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement