NYOJ 179题 LK's problem

来源:互联网 发布:华东理工大学网络 编辑:程序博客网 时间:2024/06/06 12:29

总的时间包括三部分:开门前的等待时间+排队的时间+teller服务的时间。

题目中: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 即 “你的程序应该决定安排clients进入tellerCount queues队的最好方法,使得 等待最长的client的等待时间是最小的” ;Return the minimum waiting time for the client who waits the longest 即 返回等待时间最长的人的 最小时间。

源代码:

#include<stdio.h>
int main()
{
int n;
while(scanf("%d", &n), n != 0)
{
int i,j,sum;
int a[200], t;
for(i = 1; i <= n; i ++)
scanf("%d", &a[i]);
for(i = 1; i < n; i++)//使用选择排序,注意起点改变了吗
for(j = i + 1; j < n+1; j ++)
if (a[i] < a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
int tcount, servtim, num, m;
scanf("%d %d", &tcount, &servtim);
num = n / tcount;
m = n % tcount;
if(m == 0)
sum = a[(num-1)*tcount+1] + num * servtim;//这里需注意一下;
else
sum = a[1 + num * tcount] + (num + 1) * servtim;//这里也是;
printf("%d\n", sum);
}
return 0;
}

原创粉丝点击