Nyoj 179 LK ' s problem (sort simulation)

Source: Internet
Author: User

Link: click here~~

Test instructions

DescriptionLK has a question. Coule. It is the beginning of the day at a bank, and a crowd  of clients are already waiting for the entrance door to  o Pen. 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 had  already been waiting at the moment when the bank door   Opens. Your program should determine the best by 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.& nbsp Return the minimum waiting time for the client waits the longest.
Input
The
input would consist of several test cases. For each test case, one integer n (1<= n <=) was 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, with N = 0.
Output
for each test of the input, print the answer.
Sample input
21 21 10110) 50 500

Sample output

2160
Test Instructions :before the bank opened the door, some people had been waiting at the door to handle the business. Waiting time for a person = waiting time before opening + queue time after opening + time to transact business. Each person takes the same time to transact the business, and there are no new people behind the janitor. Asking how to arrange the order of these people can make the person who waits the longest wait for the shortest time. The minimum amount of time to wait for the person with the longest waiting time.

Each group of data first entered an n, representing there are N people, the second row has n number, on behalf of each person in front of the bank waiting time, the third row has two numbers, respectively, representing the number of bank service personnel and each person to transact the business time (the same time for everyone). Output The minimum amount of time to wait for the person waiting for the longest time.

ideas :after waiting for the time in front of the door, to find out the time for each person (waiting for a long time before opening) and then the time for each person to sort, the output of the largest time

Code:

/* After waiting for time in front of the door, find out how much time each person uses (wait for a long time before opening the door) and then sort the time for each person, output the maximum 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-give up, think for why do you persist until now!

Nyoj 179 LK ' s problem (sort simulation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.