USACO section1.3 Mixing Milk 混合牛奶

题目:http://www.wzoi.org/usaco/11%5C302.asp

 

水题。。。。。。。按价格升序后,从头开始选。

 

/*
ID: qiufeih1
PROG: milk
LANG: C++
*/

#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;

const int INF = 1<<30;


struct farmer
{
int price, num;
}a[5010];


bool Cmp(farmer a, farmer b)
{
return a.price < b.price;
}
int main()
{
freopen("milk.in", "r", stdin);
freopen("milk.out", "w",stdout);
int n, m;
int star, end;
int i, j;
int ans;
int count;
int flag;
int min, max;
scanf("%d%d", &n, &m);


for (i = 0; i < m; i++)
{
scanf("%d%d", &a[i].price, &a[i].num);
}

sort(a, a+m, Cmp);

i = 0;
ans = 0;
while (n)
{
if (n >= a[i].num)
{
ans += a[i].num * a[i].price;
n -= a[i].num;
}
else
{
ans += n * a[i].price;
n = 0;
}
i++;
}

printf("%d\n", ans);

return 0;
}



你可能感兴趣的:(USACO)