ZOJ 3464 Rugby Football 水题
[cpp]//ZOJ 3464 Rugby Football
//水题
#include<stdio.h>
#include<stdlib.h>
#define N 10005
int a[N];
int n,t,l;
int cmp(const void *a,const void *b){
return *(int *)b - *(int *)a;
}
int main(){
int T;
int i;
scanf("%d",&T);
while(T--){
scanf("%d %d %d",&n,&t,&l);
for(i = 1; i <= n; ++i)
scanf("%d",&a[i]);
qsort(a+1,n,sizeof(a[0]),cmp);
double ans = 0;
for(i = 1; i <= n; ++i){
if(l >= a[i]*t){
l -= a[i]*t;
ans += t;
}
else {
ans += l*1.0/a[i];
l = 0;
break;
}
}
if(l == 0)
printf("%.2lf\n",ans);
else
printf("-1\n");
}
return 0;
}
补充:软件开发 , C++ ,