USACO1.3
#include<iostream>
#include<algorithm>
#define N 5050
using namespace std;
struct milk
{
int cost;
int num;
}p[N];
bool cmp(milk x,milk y)
{
return x.cost < y.cost;
}
int main()
{
int i;
int milk_num , man_num;
int sum = 0;
cin >> milk_num >> man_num ;
for( i = 0 ; i < man_num ; i++)
cin >> p[i].cost >> p[i].num ;
sort(p,p+man_num,cmp);
i=0;
while(1)
{
if(milk_num > p[i].num) sum+=p[i].cost*p[i].num , milk_num-=p[i].num,cout;
else {sum+=milk_num*p[i].cost;break;}
i++;
}
cout << sum;
return 0;
}
PS : 终于进了梦寐以求的暑训,发一道水题吧,这道题是我结构体入门的一道题,结构体之前不愿意用,现在反而感觉很方便,特别是类似这种链式结构。这道题是一道贪心算法的入门题。这道题题意很好理解,已在luogu上ac
PPS:希望自己在今后的路上记得自己当初为什么出发,吾与子共缅。
P1208 [USACO1.3]混合牛奶