PTA乙级 (1020 月饼 (25分))
作者:互联网
1020 月饼 (25分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805301562163200
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <vector> using namespace std; struct mooncake{ double number; double money; double pro; }; bool cmp(mooncake a,mooncake b) { return a.pro>=b.pro; } int main() { mooncake m; int N,D; cin>>N>>D; vector<mooncake> vec(N); for(int i=0;i<N;i++) cin>>vec[i].number; for(int i=0;i<N;i++) cin>>vec[i].money; for(int i=0;i<N;i++) vec[i].pro=vec[i].money/vec[i].number; sort(vec.begin(),vec.end(),cmp); double sum=0,last=0; for(int i=0;i<vec.size();i++) { if(vec[i].number>=D-last) {sum+=(D-last)*vec[i].pro; break;} else { sum+=vec[i].money; last+=vec[i].number; } } printf("%.2f\n",sum); return 0; }
标签:25,1020,int,money,pro,PTA,vec,mooncake,include 来源: https://www.cnblogs.com/jianqiao123/p/12256937.html