Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and trains from containers that have been unloaded from ships. The material from the dock is stacked (up to 5 containers high) if it to be sent by train. The materials destined to be sent by planes are are unpacked and placed on an assembly line. Each item is labeled either a train number or plane number (which is its destination). Items destined for trains are placed in a stack until it reaches 5 items high, then a new stack is begun behind the original. Items are planes are placed on a long assembly line (there is only 1 assembly line). You can assume 1 worker is loading trains and 1 worker is loading the planes at the same time. The trains (planes) closer to the dock have the smaller train (plane) numbers Each worker requires 2 minutes x train number to move an item from the dock to a train and return. Each worker required 10 minutes x the plane number to move an item from the dock to a plane and return. Given the order that items are unloaded from the ship, your job is write a program to determine the total time it will take to load all the materials.
Input:
All input will be from the keyboard. The first line of input will be 4 integers (t,p and nt and np) (0 <= t < 100, 0 <= p < 10,0 <= nt,0 <= np) (each separated by a single space), which represent the total number of trains , the total number of planes and the total number of to be loaded into trains and the total number of items to be loaded into planes. The second line will contain t integers (again separated by a single space) representing the number of items to be loaded to each train. The third line will contain p integers (again separated by a single space) representing the number of items to be loaded to each plane. The fourth line will contain nt representing the destination of each item being sent by a train. The last line will contain np representing the destination of each item being sent by a plane.
Output:
Output will be on the screen in 2 lines. The first line contains nt integers each separated by 1 space. The ith integer represents the time the ith train finished loading. The second line contains np integers each separated by 1 space. The ith integer represents the time the ith plane finished loading.
sample Input
3 2 10 5 2 7 1 3 2 2 2 2 1 3 2 2 2 1 2 2 1 1 2 1
corresponding Output
25 36 3 65 50
c++ stacks queue linked list
Code:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int p;
int nt;
int np;
// Input number of planes/trains and items
cin >> t >> p >> nt >> np;
// Arrays to store capacities of each train/plane
int train_cap[t+1];
int plane_cap[p+1];
// Arrays to store answer for each train/plane
int train_ans[t+1];
int plane_ans[p+1];
// Arrays to store item's destinations for trains/planes
int train_item[nt+1];
int plane_item[np+1];
// Input data
for(int i = 1; i <= t; i++)
cin >> train_cap[i];
for(int i = 1; i <= p; i++)
cin >> plane_cap[i];
for(int i = 1; i <= nt; i++)
cin >> train_item[i];
for(int i = 1; i <= np; i++)
cin >> plane_item[i];
// Calculate answer for trains
int timer = 0;
for(int i = 1; i <= nt; i+=5) {
stack<int> trainStack;
// Create new stack with maximum 5 elements
for(int j = i; j <= min(i+4,nt); j++)
trainStack.push(j);
// Load items to the train from the stack
while(!trainStack.empty()){
// Take item from the stack
int j = trainStack.top();
// Remove item from the stack
trainStack.pop();
// Time to reach train
timer += train_item[j];
// If train is full store ans
train_cap[train_item[j]]--;
if(train_cap[train_item[j]] == 0)
train_ans[train_item[j]] = timer;
// Time to return back
timer += train_item[j];
}
}
// Calculate answer for planes
timer = 0;
queue<int> planeQueue;
// Create queue for plane
for(int i = 1; i <= np; i++)
planeQueue.push(i);
// Load items from plane to the queue
while(!planeQueue.empty()) {
// Take new item from queue
int i = planeQueue.front();
planeQueue.pop();
// Time to reach plane
timer += plane_item[i]*5;
// If plain is full store ans
plane_cap[plane_item[i]]--;
if(plane_cap[plane_item[i]] == 0)
plane_ans[plane_item[i]] = timer;
// Time to return back
timer = timer + plane_item[i]*5;
}
// Print answers
for(int i = 1; i <= t; i++)
cout << train_ans[i] << " ";
cout << "\n";
for(int i = 1; i <= p; i++)
cout << plane_ans[i] << " ";
cout << "\n";
}
Output:
____________________________
Comment down for any queries
Please give a thumb up
Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and trains from containers...
C++ Program Description Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and trains from containers that have been unloaded from ships. The material from the dock is stacked (up to 5 containers high) if it to be sent by train. The materials destined to be sent by planes are are unpacked and placed on an assembly line. Each item is labeled either a train number or plane number (which is its destination). Items destined for trains...
You need to start doing your CST370 homework, but you don't really feel like it. You decide to take the longest route from your current location on campus to where you plan to do your homework to procrastinate a bit. You're given a graph representing CSUMB's campus, and your goal is to nd the path with the most stops to your homework destination without visiting any location more than once. Input • The first line contains your current location. •...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
in C++ and comments please for better understanding 3. How Will You Compare? Write a Comparator class with the following 3 overloaded compare methods: 1. boolean compare(int a, int b): Return true if int a = int b, otherwise return false. 2. boolean compare(string a, string b): Return true if string a = string b, otherwise return false. 3. boolean compare(int[] a, int[] b): Return true if both of the following conditions hold true: O Arrays a and b are...
[for Python 3 class; must use stdin and stdout for IO; for libraries, must import by "from x import y"] The Task Feeling sorry for all the mischief he has caused recently, Hugh Manatee has agreed to help Professor Smith stock pile bundles of seagrass at one of several docks along the Indian River Lagoon. There are N (1 <= N <= 1,000,000, N) docks conveniently numbered 1..N, initially all of them have no bundles. Professor Smith then gives Hugh...
I am stuck with this coding problem from edx coding python 4.4.6: #This is a long one -- our answer is 20 lines of code, but #yours will probably be longer. That's because it's one of the #more authentic problems we've done so far. This is a real #problem you'll start to face if you want to start creating #useful programs. # #One of the reasons that filetypes work is that everyone #agrees how they are structured. A ".png" file,...
Write a program mexp that multiplies a square matrix by itself a specified number of times、mexp takes a single argument, which is the path to a file containing a square (k × k) matrix M and a non-negative exponent n. It computes M and prints the result Note that the size of the matrix is not known statically. You ust use malloc to allocate space for the matrix once you obtain its size from the input file. Tocompute M". it...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...
JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm/ //made up data 2004/Ali/1212/1219/1 2003/Bob/1123/1222/3 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2001/Jim/1101/1201/3 Text file Class storm{ private String nameStorm; private int yearStorm; private int startStorm; private int endStorm; private int magStorm; public storm(String name, int year, int start, int end, int mag){ nameStorm = name; yearStorm = year; startStorm...