NYOJ 179题 LK's problem

总的时间包括三部分:开门前的等待时间+排队的时间+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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值