milk解题报告 —— icedream61 博客园(转载请注明出处)
------------------------------------------------------------------------------------------------------------------------------------------------
【题目】
  我是牛奶制造商,我一天需要N加仑的牛奶,总共有M个农民可以供给我。
  这M个农民的信息共M行,第i个农民有num[i]加仑牛奶,每加仑价格为price[i]。
  求我买够牛奶所需的最少钱数。
  数据保证,农民生产的牛奶总数一定是够的。
【数据范围】
  0<=N<=2,000,000
  0<=M<=5,000
  0<=price[i]<=1,000
  0<=num[i]<=2,000,000
【输入样例】
  100 5
  5 20
  9 40
  3 10
  8 80
  6 30
【输出样例】
  630
------------------------------------------------------------------------------------------------------------------------------------------------
【分析】
  排序一下,贪心即可。
------------------------------------------------------------------------------------------------------------------------------------------------
【总结】
  一遍AC。
  顺带复习了下类的运算符号重载。

------------------------------------------------------------------------------------------------------------------------------------------------

【代码】

 /*
ID: icedrea1
PROB: milk
LANG: C++
*/ #include <iostream>
#include <fstream>
using namespace std; const int maxn = ;
const int maxm = ; struct Farmer
{
int price;
int num;
friend bool operator<(Farmer const &x,Farmer const &y) { return x.price<y.price; }
}; int N,M;
Farmer F[+maxm]; void qsort(int l,int r)
{
if(l>=r) return;
int i=l,j=r;
Farmer x=F[(l+r)>>];
while(true)
{
while(F[i]<x) ++i;
while(x<F[j]) --j;
if(i>j) break;
swap(F[i],F[j]);
++i; --j;
}
qsort(l,j); qsort(i,r);
} int main()
{
ifstream in("milk.in");
ofstream out("milk.out"); in>>N>>M;
for(int i=;i<=M;++i) in>>F[i].price>>F[i].num; qsort(,M); int cost=;
for(int i=;N && i<=M;++i)
{
int num=min(N,F[i].num);
N-=num; cost+=F[i].price*num;
}
out<<cost<<endl; in.close();
out.close();
return ;
}

USACO Section1.3 Mixing Milk 解题报告的更多相关文章

  1. USACO Section1.5 Prime Palindromes 解题报告

    pprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  2. USACO Section1.5 Superprime Rib 解题报告

    sprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  3. USACO Section1.5 Number Triangles 解题报告

    numtri解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  4. USACO Section1.4 Arithmetic Progressions 解题报告

    ariprog解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...

  5. USACO Section1.3 Combination Lock 解题报告

    combo解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  6. USACO Section1.3 Prime Cryptarithm 解题报告

    crypt1解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  7. USACO Section1.3 Barn Repair 解题报告

    barn1解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  8. USACO Section1.2 Palindromic Squares 解题报告

    palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  9. USACO Section1.2 Dual Palindromes 解题报告

    dualpal解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...

随机推荐

  1. .net core 操作域控 活动目录 ladp -- Support for System.DirectoryServices for Windows

    原文链接:https://github.com/dotnet/corefx/issues/2089 1. @ianhays to kick start the project in CoreFX re ...

  2. 使用函数BAPISDORDER_GETDETAILEDLIST读取S/4HANA中Sales Order行项目数据

    事务码MM03查看物料主数据,如下图所示的行项目数据,包含物料ID,描述信息,数量,单价等等: 使用如下代码进行行项目读取: DATA: ls_read TYPE order_view, lt_ite ...

  3. java调用dll库

    1.dll叫动态链接库,作用是用某种语言封装好某些函数生成可供不同语言调用的.dll文件,通常是用C++编写生成,因为C++可以对很多硬件操作方便而其他高级语言不行 2.dll生成参考:http:// ...

  4. MHA 日常维护命令集

    MHA 日常维护命令集 1.查看ssh登陆是否成功 masterha_check_ssh --global_conf=/etc/masterha/masterha_default.conf --con ...

  5. node.js 下使用 util.inherits 来实现继承

    上一篇博客说到了node.js继承events类实现事件发射和事件绑定函数,其中我们实现了一个公用基类 _base ,然后在模型中差异化的定义了各种业务需要的模型并继承 _base 公共基类.但是其中 ...

  6. nginx 配置路由规则转发配置记录

    工作中公司要求针对经销商PC端和工厂PC端的访问地址固定访问. 经销商PC端 http://localhost/ 工厂PC端   http://localhost/fac 文件磁盘路径: /crm/n ...

  7. 11-UITableView

    UITableView 掌握 设置UITableView的dataSource.delegate UITableView多组数据和单组数据的展示 UITableViewCell的常见属性 UITabl ...

  8. pip命令小结

    pip的另一种调用方式 python -m pip通过指定python的名字来指定特定的pip pip freeze > 项目目录/requirements.txt导出pip中下载的包目录 pi ...

  9. 关于Pycharm基本操作笔记

    创建 project(工程,译音:破拽科特) 1.Create New project(创建一个新的工程,译音:科瑞特 纽 破摘科特) 2.pure python(纯派森,译音:皮忧儿 派森) 3.l ...

  10. RabbitMQ (1) 环境安装

    1.下载erlang, 设置系统的环境变量 下载地址:http://www.erlang.org/downloads ERLANG_HOME=D:\Program\erl9.3 Path = %ERL ...