题目链接:USACO 1.3.1

简单的贪心,将cent从小到大排序.

/*
ID:wang9621
PROG:milk
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct edge
{
int cent;
int unit;
};
edge per[];
bool cmp(edge a,edge b)
{
return a.cent<b.cent;
}
int main()
{
freopen("milk.in","r",stdin);
freopen("milk.out","w",stdout);
int n,m;
scanf("%d %d",&n,&m);
for(int i = ; i<=m; i++)
{
scanf("%d %d",&per[i].cent,&per[i].unit);
}
sort(per+,per+m+,cmp);
int sum = ;
for(int i = ; i<=m; i++)
{
if(n>=per[i].unit)
{
sum += per[i].cent*per[i].unit;
n -= per[i].unit;
}
else if(n>)
{
sum += n*per[i].cent;
n = ;
} }
printf("%d\n",sum);
return ;
}

最新文章

  1. Nuget 命令 NuGet 管理项目库
  2. 第一次部署Struts2时出现错误java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.class
  3. SqlDevlepor注册表监听器设置
  4. C语言 百炼成钢11
  5. iOS 键盘隐藏
  6. scala学习笔记(8): 列表的map,flatMap,zip和reduce
  7. CSDN代码片排版
  8. 一天学完UFLDL
  9. nodejs抓取网页内容
  10. 分区表在安装系统(MBR)丢失或损坏
  11. 【原创】Android 5.0 BLE低功耗蓝牙从设备应用
  12. java~google样式检查和命名规范
  13. C#之事件与eventArgs
  14. webapi put 404
  15. 分布式系统消息中间件——RabbitMQ的使用思考篇
  16. MySQL 迁移并搭建主从(实践)
  17. JS-nodejs--nodewebkit--npm穿墙cnpm
  18. Systemd 服务管理器
  19. [BZOJ5338][TJOI2018]xor(可持久化Trie)
  20. Synergy 多系统共享鼠标键盘 Windows 和 Mac 完全配置教程

热门文章

  1. linux下base命令
  2. Storm官方文档翻译之在生产环境集群中运行Topology
  3. knockout.js
  4. 在Linux中设置共享目录
  5. psql 命令总结
  6. Qt之Windows开发移植问题汇总
  7. JSP导出Excel后身份证后三位为0
  8. usb-to-isp-for-stm32
  9. 【A + B + C + D】 问题
  10. opencv-----基本数据类型