首页 > 学院 > 开发设计 > 正文

1070. Mooncake (25)

2019-11-08 02:55:26
字体:
来源:转载
供稿:网友

计算出单价,对此进行排序,然后从大到小的筛选就好了

#include<iostream>#include<vector>#include<algorithm>#PRagma warning(disable:4996)using namespace std;struct node { double n, m, p;//数量,总金额,单价 bool Operator<(const node that)const { return this->p < that.p; }};int main(){ int N, M; vector<node> all; cin >> N >> M; all.resize(N); for (int t = 0;t < N;t++) scanf("%lf", &all[t].n); for (int t = 0;t < N;t++) { scanf("%lf", &all[t].m); all[t].p = all[t].m / all[t].n; } sort(all.rbegin(), all.rend()); double resault = 0; for (auto x : all) { if (x.n > M) { resault += M*x.p;break; } if (x.n <= M) { resault += x.m; M -= x.n; } } printf("%.2lf/n", resault);}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表