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