0
3
1
王文博
缔造者之神
缔造者之神
for(int i=1;i<=n;i++)
{
if(a[i].num<t)
{
ans+=a[i].pri;
t-=a[i].num;
}
else
{
ans+=a[i].avg*t;
break;
}
}
贪心直接解决
0
0
0
李奕歌
初级天翼
初级天翼
核心:
typedef struct moon {
double weight;
double sum;
double value;
}moon;
bool cmp(moon a, moon b){
return a.value > b.value;
}
int n, need;
double w=0, cost=0;
vector<moon> t(n);
for (int i = 0; i < n; i++)
cin >> t[i].weight;
for (int i = 0; i < n; i++) {
cin >> t[i].sum;
t[i].value = t[i].sum / t[i].weight;
}
sort(t.begin(), t.end(), cmp);
int i = 0;
while (w < need&&i<n) {
if (w + t[i].weight < need) {
w = w + t[i].weight;
cost += t[i].sum;
i++;
}
else {
cost += t[i].value*(need - w);
w = need;
break;
}
}
最后四舍五入输出cost
0
0
0