ZOJ-3334 Body Check

Problem Description

Due to the spread of H1N1 all over the world, the king of Kingdom atouSK is so afraid that he decides to ask all his people to do a body check, no matter how much money it will take. Thus, the king calls upm of the best doctors across the kingdom to finish the task. The docotrs of Kingdom atouSK are selfish. If some of them are asked to work while others of them can take a rest, the docotrs who need to work will get angry and make mistakes at their work time. However, there is one exception, when just one of them needs to work and the others can have a rest, the other doctors will be united and report to the king if the working doctor makes mistakes, so the working doctor needs to do the job alone carefully (How poor!). Therefore, all them docotrs need to work together or only one of them does the work at certain time.

There are n people in Kingdom atouSK, and it takes different people differnt time to finish the body check. A person can do parts of the check by one doctor and later move to another doctor to continue the check. In other words, a person can do any part of the body check by any docotr at any time, all depending on the doctors' arrangement. But of course, a personCANNOT do the check by two or more doctors at the same time! Suppose the chosenm docotrs are so excellent that they all work at the same efficiency, but they should be focused and eachCANNOT check more than one people at the same time.

Though the king doesn't care about the money, he is so concerned about the time to finish all the checks, because the later all the checks finish, the more likely the disease will spread. The king is too busy, so he asks you to calculate the shortest time needed to finish all the body checks.

Input

There may be multiple cases. In each case, there are two integers in the first line,m (0 <m <= 1000) andn (0 <n <= 1000). In the second line, there aren positive real numbers, the ith one indicating the time needed for the ith person to finish the check, not exceeding 1000000.

Output

Output the shortest time needed to finish all the body checks in one line for each case.

Answer having a relative error less than 1e-9 will be accepted.


Sample Input

3 2
1.0 2.0
2 2
1.0 2.0
2 3
1.00 2.0 3.0

Sample Output

3.0000
2.0000
3.0000


题意:给m个医生,n个病人,用最少时间完成所有病人的体检,医生每次只能医治一个病人,并且病人不用一次在一个医生那一次性治好,即病人可以先医治一段时间,然后下一次去别的医生那医治一段时间。一个病人一次也只能在一个医生那医治

有两种处理方法:

1:所有医生一起工作,每人处理一个病人

2:当病人人数比医生人数少时,只派一个医生医治



呆哥给的思路:

1.当病人的人数比医生少时,直接输出总用时


2.计算所有病人的总用时,对病人时间从大到小排序,最高效的方法就是让全部医生一起工作的时间最大。因为病人可以分开时段去不同的医生那医治,我们把它们的时间平均分配给几个医生。如果总共有5个医生的话,共同工作最长用时相当于左数第3块。由于是从大到小排序,只需要把前两块的用时减去平均分配的时间+平均分配时间,就是总用时


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
double time[1050];
int m,n;
int imp(const void *a,const void *b){
	return (*(double *)b-*(double *)a>0?1:-1);
}
int main(void){
	while(~scanf("%d%d",&m,&n)){
		double sum=0;
		for(int i=0;i<n;i++){
			scanf("%lf",&time[i]);
			sum+=time[i];
		}
		if(n<m)
			printf("%.4f\n",sum);
		else {
			double yue=sum/m;
			int i,j;
			qsort(time,n,sizeof(time[0]),imp);
			for(i=0;i<m;i++)
				if(time[i]>yue){
					sum-=time[i];
					yue=sum/(m-i-1);
				}
				else {
					break;
				}
			double ans=yue;
			for(j=0;j<i;j++)
				ans+=time[j]-yue;
			printf("%.4f\n",ans);
		}		
	}
	return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值