Znn3bq.jpeg
²é¿´: 483  |  »Ø¸´: 1
¡¾½±Àø¡¿ ±¾Ìû±»ÆÀ¼Û1´Î£¬×÷Õßstephenliu89Ôö¼Ó½ð±Ò 0.5 ¸ö

stephenliu89

Òø³æ (СÓÐÃûÆø)


[×ÊÔ´] ¡¾Ô­´´¡¿Ò»µÀ±à³ÌÁ·Ï°Ì⣬̰ÐÄ·¨£¬¸½ÎҵĽⷨ

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' want 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
===============================================
¼òµ¥µÄ̰ÐÄ·¨ÌâÄ¿£¬ºÜÈÝÒ×AC
My Solution£º

#include
#include
using namespace std;
long int N, price = 0 ,amount = 0; //value
int M; //number of farmer
struct str
{
int P; //price
long int A; //amount
} farmer[5001],temp;
int main()
{
ifstream fin ( "milk.in" );
ofstream fout ( "milk.out" );

int i, j;
fin >> N >> M;
for ( i = 0; i < M; i++ )
   fin >> farmer[ i ].P >> farmer [ i ].A;

for ( j = M - 1; j >= 0; j--)
   for ( i = 0; i < j; i++ )
    if( farmer[ i ].P > farmer[ i + 1 ].P )
    {
     temp = farmer[ i ];
     farmer [ i ] = farmer [ i + 1 ];
     farmer [ i + 1 ] = temp;
    }
i = -1;
while ( amount < N )
{
   i++;
   if ( farmer [ i ].A <= N - amount )
   {
    price += farmer[ i ].A * farmer[ i ].P;
    amount += farmer [ i ].A;
   }
   else
   {
    price += ( N - amount ) * farmer[ i ].P;
    amount +=N - amount;
   }
}
fout << price << endl;
return 0;
}

[ Last edited by stephenliu89 on 2010-8-29 at 16:22 ]
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
¼òµ¥»Ø¸´
recen2Â¥
2010-10-28 18:11   »Ø¸´  
 
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ stephenliu89 µÄÖ÷Ìâ¸üÐÂ
¡î ÎÞÐǼ¶ ¡ï Ò»ÐǼ¶ ¡ï¡ï¡ï ÈýÐǼ¶ ¡ï¡ï¡ï¡ï¡ï ÎåÐǼ¶
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] ÉúÎïѧ308·ÖÇóµ÷¼Á£¨Ò»Ö¾Ô¸»ª¶«Ê¦´ó£©×ö¹ý·Ö×ÓʵÑé +7 ÏàÐűػá¹ââÍòÕ 2026-04-07 8/400 2026-04-10 16:53 by wrnwrn
[¿¼ÑÐ] ³õÊÔ261 +3 AshtÉÙ 2026-04-10 6/300 2026-04-10 16:38 by AshtÉÙ
[˶²©¼ÒÔ°] 0856²ÄÁÏ»¯¹¤Çóµ÷¼Á£¬Ò»Ö¾Ô¸211£¬³õÊԳɼ¨349 +5 ½­»´±±Ô 2026-04-05 5/250 2026-04-10 16:26 by ¸ßά´º
[¿¼ÑÐ] 285Çóµ÷¼Á +9 AZMK 2026-04-07 11/550 2026-04-10 15:24 by AZMK
[¿¼ÑÐ] ÖпÆÔº×Ü·Ö315Çóµ÷¼Á +7 lallalh 2026-04-09 7/350 2026-04-10 15:07 by Kilig0317
[¿¼ÑÐ] 282£¬Çóµ÷¼Á +10 jggshjkkm 2026-04-09 12/600 2026-04-10 14:53 by ÄæË®³Ë·ç
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +13 Ò»ÑùYWY 2026-04-04 13/650 2026-04-10 11:07 by mattzhming
[¿¼ÑÐ] »·¾³×¨Ë¶µ÷¼Á +16 »á˵»°µÄÖâ×Ó 2026-04-06 16/800 2026-04-10 10:30 by asy1wn
[¿¼ÑÐ] ²ÄÁÏ¿¼ÑÐÇóµ÷¼Á×Ü·Ö280 +30 mkjlz1 2026-04-06 35/1750 2026-04-08 21:25 by cyh¡ª315
[¿¼ÑÐ] 285Çóµ÷¼Á +7 ¶ñ·¨´ó¶þµÄÆøÎ¶ß 2026-04-05 10/500 2026-04-08 14:34 by zhq0425
[¿¼ÑÐ] Çó¿¼ÑвÄÁϵ÷¼Á +3 ²Ä»¯Àî¿É 2026-04-07 3/150 2026-04-08 00:21 by JourneyLucky
[¿¼ÑÐ] ÉúÎïѧ363µ÷¼ÁÇóÖú +7 fanzhang6666 2026-04-06 9/450 2026-04-07 17:37 by lijunpoly
[¿¼ÑÐ] Ò»Ö¾Ô¸ºÓ±±¹¤Òµ´óѧ²ÄÁϹ¤³Ì£¬³õÊÔ344Çóר˶µ÷¼Á +6 15933906766 2026-04-05 6/300 2026-04-06 13:21 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] ²ÄÁÏר˶322·Ö +10 ¹þ¹þ¹þºðºðºð¹þ 2026-04-04 10/500 2026-04-05 21:22 by ѧԱ8dgXkO
[¿¼ÑÐ] 315Çóµ÷¼Á +5 £¦123456789 2026-04-05 5/250 2026-04-05 19:55 by nepu_uu
[¿¼ÑÐ] 358Çóµ÷¼Á +7 Çïgk 2026-04-04 7/350 2026-04-05 13:29 by huangmoli
[¿¼ÑÐ] 288Çóµ÷¼Á£¬Ò»Ö¾Ô¸»ªÄÏÀí¹¤´óѧ071005 +6 ioodiiij 2026-04-04 6/300 2026-04-05 10:09 by guoweigw
[¿¼ÑÐ] 353Çóµ÷¼Á +10 MayUxw1 2026-04-03 10/500 2026-04-05 09:23 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] 292Çóµ÷¼Á +11 2022080213 2026-04-04 13/650 2026-04-04 18:38 by macy2011
[¿¼ÑÐ] 400·ÖÇóµ÷¼Á +3 ÞÏÞÎÇÒÄÓÍ· 2026-04-04 3/150 2026-04-04 08:41 by jp9609
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û