fork download
  1. #include<iostream>
  2. #include<sstream>
  3. using namespace std;
  4.  
  5. int M, X, Y, F;
  6. int minute;
  7.  
  8. struct Family {
  9. int ID;
  10. int num;
  11. int price;
  12. int enter_minute;
  13. };
  14.  
  15. struct Place {
  16. int total_money;
  17. int total_entered;
  18. int total_quit;
  19. int ID_counter;
  20. int register_timer;
  21. int special_family;
  22.  
  23. Family queue[20000];
  24. int queue_size;
  25. Family families_entered[20000];
  26. int families_entered_size;
  27.  
  28. Place() {
  29. total_money = 0;
  30. total_entered = 0;
  31. total_quit = 0;
  32. ID_counter = 1;
  33. register_timer = 0;
  34. special_family = -1;
  35. queue_size = 0;
  36. families_entered_size = 0;
  37.  
  38. for (int i = 0; i < 20000; i++) {
  39. queue[i].ID = -1;
  40. families_entered[i].ID = -1;
  41. }
  42. }
  43.  
  44. void helper_add_family_entered(Family family) {
  45. families_entered[families_entered_size] = family;
  46. families_entered_size++;
  47. }
  48.  
  49. void add_family_from_line(string line) {
  50. stringstream ss(line);
  51. string token;
  52. while (ss >> token) {
  53. int A, P;
  54. if (sscanf(token.c_str(), "%d,%d", &A, &P) == 2) {
  55. add_family(A, P);
  56. } else {
  57. continue;
  58. }
  59. }
  60. }
  61.  
  62. void add_family(int num, int price) {
  63. if (queue_size == 0) {
  64. register_timer = 0;
  65. }
  66. queue[queue_size].ID = ID_counter++;
  67. queue[queue_size].num = num;
  68. queue[queue_size].price = price;
  69. queue[queue_size].enter_minute = minute;
  70. queue_size++;
  71. }
  72.  
  73. void helper_shift_left_from(int idx) {
  74. for (int i = idx; i < queue_size - 1; i++) {
  75. queue[i] = queue[i + 1];
  76. }
  77. queue[queue_size - 1].ID = -1;
  78. queue_size--;
  79. if (queue_size == 0) {
  80. register_timer = -1;
  81. }
  82. }
  83.  
  84. void progress_registration() {
  85. if (queue_size > 0) {
  86. if (register_timer == 2) {
  87. register_timer = 0;
  88. int price = queue[0].price;
  89. if (special_family == queue[0].ID) {
  90. price = 0;
  91. special_family = -1;
  92. }
  93. total_money += price;
  94. total_entered += queue[0].num;
  95. helper_add_family_entered(queue[0]);
  96. helper_shift_left_from(0);
  97. }
  98. register_timer++;
  99.  
  100. }
  101. if (special_family == -1) {
  102. find_special();
  103. }
  104. }
  105.  
  106. void find_special() {
  107. for (int i = 0; i < queue_size; i++) {
  108. int sum = 0;
  109. for (int j = i; j < queue_size - 1; j++) {
  110. sum += queue[j].price;
  111. if (sum == Y) {
  112. special_family = queue[j + 1].ID;
  113. return;
  114. }
  115. }
  116. }
  117. }
  118.  
  119. void quit_family() {
  120. for (int i = queue_size - 1; i >= 0; i--) {
  121. if (i <= X)
  122. return;
  123. if (queue[i].ID == special_family)
  124. return;
  125. if (queue[i].num >= 100)
  126. continue;
  127.  
  128. if (minute - queue[i].enter_minute >= 60) {
  129. total_quit += queue[i].num;
  130. helper_shift_left_from(i);
  131. }
  132. }
  133. }
  134.  
  135. void summary(int index) {
  136. cout << "Place " << index << " Summary\n";
  137. cout << "Total Money: " << total_money << "\n";
  138. cout << "Total People Entered: " << total_entered << "\n";
  139. cout << "Total People Quit: " << total_quit << "\n";
  140. int current_num = 0;
  141. for (int i = 0; i < queue_size; i++) {
  142. current_num += queue[i].num;
  143. }
  144. cout << "Current People Queuing: " << current_num << "\n";
  145. cout << "\n";
  146. cout << "Entered Families :\n";
  147. for (int i = families_entered_size - 1; i >= 0; i--) {
  148. cout << "Family " << families_entered[i].ID << " with " << families_entered[i].num << " people\n";
  149. }
  150.  
  151. }
  152.  
  153. void helper_print_queue() {
  154. cout << "Queue: ";
  155. for (int i = 0; i < queue_size; i++) {
  156. cout << queue[i].ID << " " << queue[i].num << " " << queue[i].price << " " << queue[i].enter_minute << "\n";
  157. }
  158. cout << "\n";
  159. }
  160. };
  161.  
  162.  
  163.  
  164. int main() {
  165. cin >> F >> X >> Y >> M;
  166. cin.ignore();
  167.  
  168. Place *places = new Place[F];
  169.  
  170.  
  171. for (int i = 0; i < F; i++) {
  172. // Input format is A,P A,P ...
  173. string line;
  174. getline(cin, line);
  175. places[i].add_family_from_line(line);
  176. }
  177.  
  178. for (minute=0; minute <= M; minute++) {
  179. cin.ignore();
  180.  
  181. for (int place_idx = 0; place_idx < F; place_idx++) {
  182. string line;
  183. getline(cin, line);
  184.  
  185. places[place_idx].progress_registration();
  186. places[place_idx].quit_family();
  187. places[place_idx].add_family_from_line(line);
  188.  
  189. if (place_idx == 0) {
  190. cout << "Minute " << minute << "\n";
  191. places[place_idx].helper_print_queue();
  192. }
  193. }
  194. }
  195.  
  196. for (int i = 0; i < F; i++) {
  197. places[i].summary(i);
  198. cout << "\n";
  199. }
  200. return 0;
  201. }
  202.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty