hdu2570 迷瘴
2011-05-19 19:33
295 查看
简单的贪心,注意精度问题
#include <iostream>
using namespace std;
int cmp(int a, int b)
{
return a<b;
}
int main()
{
int t;
int a[110];
scanf("%d", &t);
while (t --){
int n, v, w;
scanf("%d%d%d", &n, &v, &w);
for (int i = 0; i < n; i ++){
scanf("%d", &a[i]);
}
sort(a, a+n, cmp);
double sum = 0;
int totv = 0;
double non = 0;
for (int i = 0; i < n; i ++){
if ((sum + a[i]*1.0*v/100)/(totv+v) <= w*0.01){
sum += a[i]*(1.0*v/100), totv+=v;
}
else break;
}
if (totv==0){printf("0 0.00/n");}
else {
non = sum*1.0/totv;
if (non <= w*1.0/100){
printf("%d %.2lf/n", totv, non);
}
else printf("0 0.00/n");
}
}
return 0;
}
#include <iostream>
using namespace std;
int cmp(int a, int b)
{
return a<b;
}
int main()
{
int t;
int a[110];
scanf("%d", &t);
while (t --){
int n, v, w;
scanf("%d%d%d", &n, &v, &w);
for (int i = 0; i < n; i ++){
scanf("%d", &a[i]);
}
sort(a, a+n, cmp);
double sum = 0;
int totv = 0;
double non = 0;
for (int i = 0; i < n; i ++){
if ((sum + a[i]*1.0*v/100)/(totv+v) <= w*0.01){
sum += a[i]*(1.0*v/100), totv+=v;
}
else break;
}
if (totv==0){printf("0 0.00/n");}
else {
non = sum*1.0/totv;
if (non <= w*1.0/100){
printf("%d %.2lf/n", totv, non);
}
else printf("0 0.00/n");
}
}
return 0;
}