文章
85
粉丝
0
获赞
315
访问
6.1k
#include <bits/stdc++.h>
using namespace std;
typedef struct question {
double w;//题数
double m;//体力
}q;
bool cmp(question a, question b) {
return a.m/a.w<b.m/b.w;
}
int main() {
int total,n;
while(cin>>total>>n) {
if(total==-1||n==-1) {
break;
}
vector<question> v;
for(int i=0;i<n;i++) {
double x,y;
cin>>x>>y;
v.push_back({x,y});
}
double ans=0;
sort(v.begin(),v.end(),cmp);
for(int i=0;i<n;i++) {
if (total>=v[i].m) {
total-=v[i].m;
ans+=v[i].w;
}
else {
ans+=total/v[i].m*v[i].w;
break;
}
}
printf("%.3lf\n",ans);
}
}
登录后发布评论
暂无评论,来抢沙发