基于王道机试指南题
2018年1月20日22:38:04
贪心算法笔记
例题2.11
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct goods{
double price;
double pound;
double value;
}goods;
bool cmp(goods a,goods b)
{
return a.value>b.value;
}
goods buf[1000];
int main()
{
int m;//pound
int n;//price
while(scanf("%d %d",&m,&n)!=EOF)
{
if(m==-1&&n==-1)
{
break;
}
for(int i=0;i<n;i++)
{
scanf("%lf %lf",&buf[i].pound,&buf[i].price);//注意输入顺序pound和price别弄混了
buf[i].value = buf[i].pound/buf[i].price;
}
sort(buf,buf+n,cmp);
int idx=0;
doub