#include<iostream>#include<vector>#include<algorithm>
using namespace std;struct cake{double store;double sell;double price;};
bool cmp(cake a, cake b){return a.price > b.price;}
vector<cake> cakes;voidp(vector<cake> cakes){for(auto i : cakes){printf("%f %f %f\n", i.store, i.sell, i.price);}}voidtest(){int n;double m;
cin >> n >> m;
cake a;while(n--){
cin >> a.store;
cakes.push_back(a);}for(int i =0; i < cakes.size();++i){
cin >> a.sell;
cakes[i].sell = a.sell;
cakes[i].price = cakes[i].sell / cakes[i].store;}sort(cakes.begin(), cakes.end(),cmp);double sum =0;for(auto i : cakes){if(i.store <= m){
sum += i.sell;
m -= i.store;}else{
sum = sum + i.price*m;break;}}printf("%.2lf", sum);}intmain(){test();system("pause");return0;}
B1023 20’ 贪心 easy
#include<iostream>#include<vector>#include<cstdio>
using namespace std;voidtest(){int a[10];for(int i =0; i <10;++i)scanf_s("%d",&a[i]);for(int i =1; i <10;++i){if(a[i]>0){
cout << i;
a[i]--;break;}}for(int i =0; i <10;++i){for(int j =0; j < a[i];++j){
cout << i;}}}intmain(){test();system("pause");return0;}