DOJ-team-match 7-采购奖品
思路:非常简单,按物品的单价排序,商品的单价小,我们就尽量多的选它
代码:
#include<bits/stdc++.h>
using namespace std;
struct node
{
int cost,num;
}a[110];
int n,m,ans,money;
bool cmp(node x,node y)
{
return x.cost<y.cost;
}
int main()
{
cin>>m>>n;
for(int i=0;i<n;i++)
cin>>a[i].cost>>a[i].num;
sort(a,a+n,cmp);
for(int i=0;i<n && money<=m;i++)
{
if(money+a[i].cost*a[i].num>m)
{
ans+=(m-money)/a[i].cost;
money+=((m-money)/a[i].cost)*a[i].cost;
break;
}else
{
ans+=a[i].num;
money+=a[i].num*a[i].cost;
}
}
cout<<ans<<endl;
return 0;
}
标签:DOJ,num,int,money,ans,cost,team,match
From: https://www.cnblogs.com/lyk2010/p/17850365.html