USACO Section1.3 Mixing Milk 解题报告
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 解题报告的更多相关文章
- USACO Section1.5 Prime Palindromes 解题报告
pprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.5 Superprime Rib 解题报告
sprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.5 Number Triangles 解题报告
numtri解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.4 Arithmetic Progressions 解题报告
ariprog解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...
- USACO Section1.3 Combination Lock 解题报告
combo解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- USACO Section1.3 Prime Cryptarithm 解题报告
crypt1解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.3 Barn Repair 解题报告
barn1解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- USACO Section1.2 Palindromic Squares 解题报告
palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...
- USACO Section1.2 Dual Palindromes 解题报告
dualpal解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...
随机推荐
- Linux 使用第三方邮箱发邮件的设置
mail命令在Ubuntu下是需要安装的,使用下条命令进行安装: sudo apt-get install heirloom-mailx 在CentOS 下安装则是: yum install mail ...
- WINCC runtime连接SIMOTION simulator SIMOSIM
测试使用的软件版本 TIA Portal V14sp1 Windows7 sp1 (professional) Scout 5.1(integrated in TIA 集成项目) VMware wor ...
- Last_SQL_Errno: 1050
主库上create table,从库上存在. 报错信息如下所示: Last_SQL_Errno: 1050 Last_SQL_Error: ...
- ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id
远程删除key ssh-keygen -f "~/.ssh/known_hosts" -R 192.168.0.34 如果还是不可以,通过 ssh-keygen 重新生成key
- 广搜最短路(最短时间到达目的地),POJ(3669)
题目链接:http://poj.org/problem?id=3669 解题报告: 1.流星坠落的点,四周和自己本身都被毁灭,不断更新每个点被毁灭的时候的最短时间. 2.搜索终点是,到达某个点,这个不 ...
- 【转】jpg png区别和使用
为什么想整理这方面的类容,我觉得就像油画家要了解他的颜料和画布.雕塑家要了解他的石材一样,作为网页设计师也应该对图片格式的特性有一定了解,这样才能更好的表达你的创意和想法. 除此之外,我们在平时工作中 ...
- 【转】Android xml资源文件中@、@android:type、@*、?、@+含义和区别
一.@代表引用资源 1.引用自定义资源.格式:@[package:]type/name android:text="@string/hello" 2.引用系统资源.格式:@andr ...
- python2.7 加密模块 解决各种坑
1 Python27 安装crypto Windows安装 在Windows上安装的时候直接 pip install pycrypto会报错,参考:http://blog.csdn.net/teloy ...
- caffe在 14.04安装
同事安装遇到的问题,记录一下 需要把cuda里面带的opengl不安装才行,否则冲突.在安装时,首先和之前一样,切换到无图形界面,关掉lightdm,安装cuda时选择--no-opengl-lib, ...
- 【课堂笔记精选】为了能够用“Unity”软件做游戏,我要从最基础的开始复习JavaScript
[声明]在“随笔”模块,只是知识点,但是在“文章”模块(https://www.cnblogs.com/Robot-DX3906/articles/10579584.html)里面,有更多内容. 20 ...