NYOJ 179 LK's problem (sorting simulation), nyojlk
Link: click here ~~
Question:
DescriptionLK has a question. Coule you help her? It is the beginning of the day at a bank, and a crowd of clients is already waiting for the entrance door to open. once the bank opens, no more clients arrive, and tellerCount tellers begin serving the clients. A teller takes serviceTime minutes to serve each client. clientArrivals specifies how long each client has already been waiting at the moment when the bank door opens. your program shocould determine the best way to arrange the clients into tellerCount queues, so that the waiting time of the client who waits longest is minimized. the waiting time of a client is the sum of the time the client waited outside before the bank opened, the time the client waited in a queue once the bank opened until the service began, and the service time of the client. return the minimum waiting time for the client who waits the longest.
-
Input
-
The input will consist of several test cases. for each test case, one integer N (1 <= N <= 100) is given in the first line. second line contains N integers telling us the time each client had waited. third line contains tow integers, teller's count and service time per client need. the input is terminated by a single line with N = 0.
-
Output
-
For each test of the input, print the answer.
-
Sample Input
-
21 21 10110 50 500
Sample output
2160
Question
:Before the bank opens the door, some people are waiting for business processing at the door. Waiting time for a person = waiting time before opening the door + waiting time after opening the door + waiting time for handling the business. Each person takes the same time to handle the business, and no new person is added after the visit. Ask how to arrange the order of these people so that the person with the longest wait time can be the shortest. Find the minimum value of the person with the longest wait time.
Input N for each group of data, which indicates that there are N people, N for the second row, that is, the waiting time for each person before the bank opens the door, and 2 for the third row, the number of bank service personnel and the time used by each person to handle the business respectively (the same time for each person ). output the minimum value of the person with the longest wait time.
Ideas: First sort the waiting time before opening the door, find the time used by each person (waiting for a long time before opening the door), then sort the time used by each person, and output the maximum time
Code:
/* Sort the waiting time before opening the door, find the time used by each person (wait for a long time before opening the door), and then sort the time used by each person, the maximum output time */# include <stdio. h> # include <string. h ># include <iostream >#include <algorithm> using namespace std; # define Max (a, B) {a> B? A: B} int Time [110], dp [110]; int main () {int n, m, I, j, a, B; while (cin> n & n! = 0) {for (I = 0; I <n; I ++) cin> Time [I]; cin> a> B; sort (Time, time + n); for (j = 0, I = n-1; I> = 0; I = I-a, j ++) dp [j] = Time [I] + B * (j + 1); sort (dp, dp + j); cout <dp [J-1] <endl ;} return 0 ;}
When you want to give up, think of why you persist until now!