SHARE
TWEET

Untitled

a guest Mar 21st, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. /*
  9. People are waiting for an elevator in a hotel. The elevator has limited capacity and you would like to analyse its movement.
  10.  
  11. The hotel has floors numbered from 0 (ground floor) to M. The elevator has a maximum capacity of X people and a weight limit of Y.
  12. There are N people gathered at the ground floor, standing in a queue for the elevator.
  13. You are given every person's weight
  14. A[K]
  15. And target floor:
  16. B[K]
  17.  
  18. A[0] and B[0] represent the first person in the queue.
  19. ----
  20. People continue to enter the elevator, in order of their position in the queue (and puish the buttons for their target floors) for as long as there is room for htem.
  21.  
  22. THE QUEUE ORDER CANNOT BE CHANGED
  23.  
  24. Elevetor goes up and stops at every selected floor, and finally returns to the ground floor.
  25.  
  26. This process is repeated until there are no more people in the queue. The goal is to count the total number of times that the elevator stops
  27.  
  28. E.G
  29. M = 0-5
  30. X = 2
  31. Y = 200
  32.  
  33. A[0] = 60       B[0] = 2
  34. A[1] = 80       B[1] = 3
  35. A[2] = 40       B[2] = 5
  36. */
  37.  
  38. int solution(vector<int> &A, vector<int> &B, int M, int X, int Y) {
  39.     std::set<int> floors;
  40.     int N = A.size();
  41.     // M number of floors from 0 - ?
  42.     // A[i] & B[i] are the ith person on the floor,
  43.     // X is elevator capacity, Y is the weight_limit
  44.     int idx = 0;
  45.     int answers = 0;
  46.     int test = 0;
  47.     while (idx < N) {
  48.         int capacity = 0;
  49.         int total_weight = 0;
  50.  
  51.         // While capacity < elevator capacity
  52.         while (idx < N && capacity < X && (total_weight + A[idx]) <= Y) {
  53.  
  54.             total_weight = total_weight + A[idx];
  55.             floors.insert(B[idx]);
  56.  
  57.             capacity++;
  58.             idx++;
  59.         }
  60.         answers = answers + floors.size();
  61.  
  62.     }
  63.     return answers;
  64. }
  65.  
  66.  
  67. int main(int, char* args[]) {
  68.  
  69.     vector<int> A, B;
  70.     int X, Y, M;
  71.  
  72.     /*
  73.     X = 5;
  74.     Y = 200;
  75.     A = { 60, 80, 40 };
  76.     B = { 2, 3, 5 };
  77.     M = 5;
  78.     */
  79.     M = 3;
  80.     X = 5;
  81.     Y = 200;
  82.     A = { 40, 40, 100, 80, 20 };
  83.     B = { 3, 3, 2, 2, 3 };
  84.  
  85.     cout << solution(A, B, M, X, Y) << endl;
  86.  
  87.     system("pause");
  88.     return 0;
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top