贪心,水题
本题要点:
1、药物按浓度从小到大排序:
如果当前的药物加入溶液中,总浓度小于 w的,就加入该溶液。否则,结束。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MaxN = 110;
int T, n, v, w;
int p[MaxN];
void solve()
{
int cnt = 0;
int W = 0;
sort(p + 1, p + n + 1);
for(int i = 1; i <= n; ++i)
{
if(p[i] <= w || (W + p[i]) <= w * (cnt + 1))
{
cnt++;
W += p[i];
}else{
break;
}
}
if(0 == cnt)
{
printf("0 0.00\n");
return;
}
printf("%d %.2lf\n", cnt * v, 0.01 * W / (1.0 * cnt));
}
int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%d%d%d", &n, &v, &w);
for(int i = 1; i <= n; ++i)
{
scanf("%d", &p[i]);
}
solve();
}
return 0;
}
/*
3
1 100 10
100
2 100 24
20 30
3 100 24
20 20 30
*/
/*
0 0.00
100 0.20
300 0.23
*/