博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1.3.1 Mixing Milk
阅读量:4309 次
发布时间:2019-06-06

本文共 2306 字,大约阅读时间需要 7 分钟。

Mixing Milk

Since milk packaging is such a low margin business, it is important to keep the price of the raw product (milk) as low as possible. Help Merry Milk Makers get the milk they need in the cheapest possible manner.

The Merry Milk Makers company has several farmers from which they may buy milk, and each one has a (potentially) different price at which they sell to the milk packing plant. Moreover, as a cow can only produce so much milk a day, the farmers only have so much milk to sell per day. Each day, Merry Milk Makers can purchase an integral amount of milk from each farmer, less than or equal to the farmer's limit.

Given the Merry Milk Makers' daily requirement of milk, along with the cost per gallon and amount of available milk for each farmer, calculate the minimum amount of money that it takes to fulfill the Merry Milk Makers' requirements.

Note: The total milk produced per day by the farmers will be sufficient to meet the demands of the Merry Milk Makers.

PROGRAM NAME: milk

INPUT FORMAT

Line 1: Two integers, N and M. 
The first value, N, (0 <= N <= 2,000,000) is the amount of milk that Merry Milk Makers wants per day. The second, M, (0 <= M <= 5,000) is the number of farmers that they may buy from. 
Lines 2 through M+1: The next M lines each contain two integers, Pi and Ai
Pi (0 <= Pi <= 1,000) is price in cents that farmer i charges.
Ai (0 <= Ai <= 2,000,000) is the amount of milk that farmer i can sell to Merry Milk Makers per day.

 

SAMPLE INPUT (file milk.in)

100 55 209 403 108 806 30

OUTPUT FORMAT

A single line with a single integer that is the minimum price that Merry Milk Makers can get their milk at for one day.

SAMPLE OUTPUT (file milk.out)

630
{
ID: makeeca1PROG: milkLANG: PASCAL}program milk;var a,p:array[1..5000]of longint; i,n,m,ans:longint;procedure qsort(l,r:longint);var i,j,t,x:longint;begin i:=l;j:=r;x:=a[random(r-l+1)+l]; repeat while a[i]
x do dec(j); if i<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t; t:=p[i];p[i]:=p[j];p[j]:=t;inc(i);dec(j);end; until i>j; if i
0 then begin dec(n,p[i]);inc(ans,a[i]*p[i]);end else begin inc(ans,n*a[i]);break;end; writeln(ans); close(output);end.

转载于:https://www.cnblogs.com/makeecat/archive/2012/10/03/usaco-milk.html

你可能感兴趣的文章
设计模式19_状态
查看>>
设计模式20_观察者
查看>>
vnpy学习10_常见坑02
查看>>
用时三个月,终于把所有的Python库全部整理了!拿去别客气!
查看>>
pd.stats.ols.MovingOLS以及替代
查看>>
vnpy学习11_增加测试评估指标
查看>>
资金流入流出计算方法
查看>>
海龟交易法则07_如何衡量风险
查看>>
海龟交易法则08_风险与资金管理
查看>>
海龟交易法则09_海龟式积木
查看>>
海龟交易法则10_通用积木
查看>>
海龟交易法则14_掌控心魔
查看>>
海龟交易法则16_附原版海龟交易法则
查看>>
克罗谈投资策略01_期货交易中的墨菲法则
查看>>
克罗谈投资策略02_赢家和输家
查看>>
克罗谈投资策略03_你所期望的赌博方式
查看>>
克罗谈投资策略04_感觉与现实
查看>>
通向财务自由之路01_导读
查看>>
通向财务自由之路02_成功的决定因素:你
查看>>
中低频量化交易策略研发01_引言
查看>>