A Zoo consists of a lion museum and a zoo for safari riding. There are many passengers and n single-passenger cars. Passengers wander around the museum for a while and then line up at the zoo gate to take a ride in a safari car.
Note that each passenger is allowed for one ride only.
When a car is available, it loads the one passenger it can hold and rides the zoo for a specific amount of time say p.
If all the n cars are out riding passengers around, then a passenger who wants a ride waits.
if a car is ready to load but there are no waiting passengers, then the car waits.
After every r units of time one passenger from the museum gets ready to take the safari car ride.
Assume that Zoo is open for k units of time. Can you find the status of the passengers and safari cars after k units of time.
Input:
First line contains an integer N number of test cases.
Each of the following N lines contains input data, separated by single space, for different test cases in the given order:
No. of Safari Cars
No. passengers in Museum at time zero
No. of passengers at zoo gate ready for ride at time zero.
p (When a car is available, it loads the one passenger it can hold and rides the zoo for a specific amount of time say p. ),
r (After every r units of time one passenger from the museum gets ready to take the safari car ride.)
k (Zoo is open for k units of time.)
Output:
Each of n lines in the output has four integers separated by as space representing :
No. of cars waiting at the zoo gate
No. of passengers completed the zoo ride
No. of passengers wandering in the museum
No. of passengers still waiting to take a ride respectively
#include <stdio.h> #define min(A,B) ((A)>(B)?(B):(A)) #define max(A,B) ((A)>(B)?(A):(B)) int main(void) { int testCount; scanf("%d", &testCount); while (testCount--){ int cars, wander, ready, p, r, k; int doneCount, ridingCount, carsWaiting; int carArrives[50]; int becomeReady[5100],nextCar,totalPeople,i; scanf("%d %d %d %d %d %d", &cars, &wander, &ready, &p, &r, &k); if (cars == 0){ int movedToReady = min(wander, k/r); printf("0 0 %d %d\n", wander - movedToReady, ready + movedToReady); continue; } doneCount = ridingCount = 0; for (i = 0; i < cars; i++) carArrives[i] = 0; totalPeople = wander+ready; for (i = 0; i < ready; i++) becomeReady[i] = 0; for (i = ready; i < totalPeople; i++) becomeReady[i] = (i-ready+1)*r; nextCar = 0; for (i = 0; i < totalPeople; i++){ int readyTime = becomeReady[i]; if (readyTime > k) break; if (carArrives[nextCar] > readyTime) readyTime = carArrives[nextCar]; carArrives[nextCar] = readyTime + p; nextCar = (nextCar+1) % cars; if (readyTime + p <= k) doneCount++; else if (readyTime <= k) ridingCount++; } carsWaiting = 0; for (i = 0; i < cars; i++) if (carArrives[i] <= k) carsWaiting++; printf("%d %d %d %d\n", carsWaiting, doneCount, max(0, wander - k/r), ready + min(wander, k/r) - doneCount - ridingCount); } return 0; }
INPUT_1:
3
4 33 6 5 2 14
6 21 4 2 2 18
5 17 4 8 5 2
OUTPUT:
0 8 26 1
5 12 12 0
3 6 13 0
INPUT_2:
2
17 165 15 9 7 12
21 152 11 7 5 10
OUTPUT:
16 15 164 0
19 11 150 0
ILLUSTRATION
Morae Q!
- Find the number of strings made by using each alphabet as starting character.
- Find the Pythagorean triplet.
- Find out what is the minimum possible energy he needs to spend.
- Sort the array in non-decreasing order and print out the original indices of sorted array.
- Compute the number of landmasses on the planet after all the meteorites have fallen.
- Give the appropriate server status as output.
- Regular expressions (Regex) using search module in python.
- Find the minimum distance between any pair of equal elements in the array.
- Find the total number of matching pairs of socks that are available.
- Find the total number of teams which can work together and cannot work together.
- Given the heights of all the boys and girls tell whether it is possible for all boys to get a girl.
- Find the sequence of cities to visit according to coordinates and conditions.
- Find the number of unique patches of rectangular land to grow samba(rice) in.
- Regular expression Regex matching strings.
- Generate a greeting quote for admin.
- Find all the cavities on the map and replace their depths with the character X.
- Check whether the given graph is Bipartite or not.
- Find the status of the passengers and safari cars at zoo after k units of time.
- Determine the chair number occupied by the child who will receive that chocolate.
- Check if Rubik’s cube of any dimensions can be assembled.