一道很水的贪心是re,帮我看看好嘛
http://paste.#include<iostream>
#include<algorithm>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<functional>
using namespace std;
int main(){
while(1){
vector<double> vector1,vector2,vector3;
int food,room;
double sum=0;
cin>>food>>room;
if(food==-1&&room==-1) break;
for(int i=0;i<room;i++){
double temp1,temp2;
cin>>temp1>>temp2;
vector1.push_back(temp1);
vector2.push_back(temp2);
double temp3= temp1/temp2;
vector3.push_back(temp3);
}
while(food!=0){
vector<double>::iterator p=max_element(vector3.begin(),vector3.end());
int x=distance(vector3.begin(),p);
// cout<<x<<"*"<<endl<<*p<<endl;
if(vector2[x]>=food) {
sum += (food/vector2[x]*vector1[x]);
cout<<fixed<<setprecision(3)<<sum<<endl;
food=0;
}
else {
food -=vector2[x];
sum +=vector1[x];
vector3[x]=0;
// cout<<sum<<endl;
}
}
}