题目大意:
给出m个农夫的产量和价格以及你的需求量,求出最小花费。
思路:
最典型的贪心题,思路见代码。
代码:
/*
ID: lujunda1
LANG: C++
PROG: milk
*/
#include
#include
#include
#include
#include
using namespace std;
struct point
{
int price;
int amount;
}famer[5000];
int cmp(const void* m,const void* n)
{
return (*(point*)m).price-(*(point*)n).price;
}
int main()
{
freopen("milk.in","r",stdin);
freopen("milk.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;ifamer[i].amount?famer[i].amount*famer[i].price:n*famer[i].price;
n-=n>famer[i].amount?famer[i].amount:n;
}
printf("%d\n",sum);
}