179.LK's problem

来源:互联网 发布:综漫 收集数据做主神 编辑:程序博客网 时间:2024/06/06 07:09

LK's problem

时间限制:3000 ms  |  内存限制:65535 KB
难度:1
描述
LK 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 should 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.
输入
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.
输出
For each test of the input, print the answer.
样例输入
21 21 10110 50 500
样例输出
2160
来源
TOPCODER
上传者
iphxer



思路:按等待时间从大到小进行排列,再依次加上服务时间(等待时间长的先开始被服务),求出每个客户所需时间(其中有些明显时间更短者不被记录),再排序输出时间最大的那个即可。

#include<iostream>#include<algorithm>using namespace std;int main() {  int N;  while(cin >> N && N) {    int a[105]={0}, b[105]={0};    for(int z = 0; z < N; z++) cin >> a[z];    sort(a, a+N);    int x, y, i, j;    cin >> x >> y;  //x表示的是出纳员的人数     for(i = N-1, j = 0; i >= 0; i=i-x, j++) {      b[j] = a[i]+y*(j+1);    }    sort(b, b+j, greater<int>() );    cout << b[0] << endl;          }}