日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NYOJ 179 LK's problem

發布時間:2025/3/16 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NYOJ 179 LK's problem 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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.
樣例輸入
2 1 2 1 10 1 10 50 50 0

樣例輸出

21 60 題意銀行開門之前,一些人已經在門口等著辦理業務。一個人等待的時間=開門前等待時間+開門后排隊時間+辦理業務所用時間。每個人辦理業務所用時間相同,且看門后沒有新增的人。問如何安排這些人的次序,能夠使得等待時間最長的那個人等待的時間最短。求等待時間最長的那個人等待的時間的最小值。

? ? ? ?每組數據先輸入一個N,代表有N個人,第二行有N個數,代表每個人在銀行開門前的等待時間,第三行有二個數,分別代表銀行服務人員的個數和每個人辦理業務所用的時間(每個人所用時間相同).輸出等待時間最長的那個人等待的時間的最小值。

? ? ? ? ?剛開始看完這個題,我的想法是這樣的:先對每個人的等待時間排序,然后求出開門前等待時間最短的那個人所用的時間就行了。后來仔細想想不行,比如

5

1 2 3 4 5

2 1

這組數據,如果用那種方法做,最短時間為3,而實際上應該是6。

所以應該是先對開門前等待時間排序后,求出每一個人所用的時間(開門前等待時間長的先辦理),然后再對每個人所用時間排序,輸出最大的那個時間即可。感覺有點貪心算法的思想。

代碼:

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() {int n,a[102],i,t,c,min,s[102],j,p;while(~scanf("%d",&n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);/*對開門前的等待時間排序*/scanf("%d%d",&c,&t);memset(s,0,sizeof(s));j=0,p=1;for(i=n-1;i>=0;i--){if(j==c){p++;j=0;}j++;s[i]=a[i]+p*t; /*求出每個人所用的時間*/}sort(s,s+n); /*再次排序*/printf("%d\n",s[n-1]); /*輸出最大值*/}return 0; }


總結

以上是生活随笔為你收集整理的NYOJ 179 LK's problem的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。