文章
1
粉丝
58
获赞
0
访问
644
#include<bits/stdc++.h>
using namespace std;
struct node {
double m,w;
}p[1005];
bool cmp(node a, node b) {
return a.m/a.w < b.m/b.w;
}
int main() {
int x,n;
while(cin >> x >> n){
if(x == -1 && n == -1){
break;
}
for(int i = 1; i <= n; i++){
cin >> p[i].m >> p[i].w;
}
sort(p + 1, p + n + 1, cmp);
double sum = 0.0;
for(int i = 1; i <=n; i++){
if(x >=p[i].w){
sum += p[i].m;
x -= p[i].w;
&...
登录后发布评论
cmp里大小反了