zoukankan      html  css  js  c++  java
  • 2020: [Usaco2010 Jan]Buying Feed, II

    2020: [Usaco2010 Jan]Buying Feed, II

    Time Limit: 3 Sec  Memory Limit: 64 MB
    Submit: 220  Solved: 162
    [Submit][Status]

    Description

    (buying.pas/buying.in/buying.out 128M 1S) Farmer John needs to travel to town to pick up K (1 <= K <= 100) pounds of feed. Driving D miles with K pounds of feed in his truck costs D*K cents. The county feed lot has N (1 <= N <= 100) stores (conveniently numbered 1..N) that sell feed. Each store is located on a segment of the X axis whose length is E (1 <= E <= 350). Store i is at location X_i (0 < X_i < E) on the number line and can sell FJ as much as F_i (1 <= F_i <= 100) pounds of feed at a cost of C_i (1 <= C_i <= 1,000,000) cents per pound. Amazingly, a given point on the X axis might have more than one store. FJ starts at location 0 on this number line and can drive only in the positive direction, ultimately arriving at location E, with at least K pounds of feed. He can stop at any of the feed stores along the way and buy any amount of feed up to the the store's limit. What is the minimum amount FJ has to pay to buy and transport the K pounds of feed? FJ knows there is a solution. Consider a sample where FJ needs two pounds of feed from three stores (locations: 1, 3, and 4) on a number line whose range is 0..5: 0 1 2 3 4 5 +---|---+---|---|---+ 1 1 1 Available pounds of feed 1 2 2 Cents per pound It is best for FJ to buy one pound of feed from both the second and third stores. He must pay two cents to buy each pound of feed for a total cost of 4. When FJ travels from 3 to 4 he is moving 1 unit of length and he has 1 pound of feed so he must pay 1*1 = 1 cents. When FJ travels from 4 to 5 he is moving one unit and he has 2 pounds of feed so he must pay 1*2 = 2 cents. The total cost is 4+1+2 = 7 cents.

    FJ开车去买K份食物,如果他的车上有X份食物。每走一里就花费X元。 FJ的城市是一条线,总共E里路,有E+1个地方,标号0~E。 FJ从0开始走,到E结束(不能往回走),要买K份食物。 城里有N个商店,每个商店的位置是X_i(一个点上可能有多个商店),有F_i份食物,每份C_i元。 问到达E并买K份食物的最小花费

    Input

    第1行:K,E,N 第2~N+1行:X_i,F_i,C_i.

    Output

     

    Sample Input

    2 5 3
    3 1 2
    4 1 2
    1 1 1

    Sample Output

    7

    HINT

    在离家较近的两家商店里各购买一吨饲料,

    则花在路上的钱是 1 + 2 = 3,花在店里的钱是2 + 2 = 4

    Source

    Silver

    题解:连DP都免了——规律很明显直接扫一遍排个序完事

     1 /**************************************************************
     2     Problem: 2020
     3     User: HansBug
     4     Language: Pascal
     5     Result: Accepted
     6     Time:0 ms
     7     Memory:1396 kb
     8 ****************************************************************/
     9  
    10 var
    11    i,j,k,l,m,n,t,v:longint;
    12    a:array[0..100000,1..3] of longint;
    13 procedure swap(var x,y:longint);inline;
    14           var z:longint;
    15           begin
    16                z:=x;x:=y;y:=z;
    17           end;
    18 procedure sort(l,r:longint);inline;
    19           var i,j,x,y:longint;
    20           begin
    21                i:=l;j:=r;x:=a[(l+r) div 2,3];
    22                repeat
    23                      while a[i,3]<x do inc(i);
    24                      while a[j,3]>x do dec(j);
    25                      if i<=j then
    26                         begin
    27                              swap(a[i,1],a[j,1]);
    28                              swap(a[i,2],a[j,2]);
    29                              swap(a[i,3],a[j,3]);
    30                              inc(i);dec(j);
    31                         end;
    32                until i>j;
    33                if i<r then sort(i,r);
    34                if l<j then sort(l,j);
    35           end;
    36 begin
    37      readln(m,t,n);
    38      for i:=1 to n do readln(a[i,1],a[i,2],a[i,3]);
    39      for i:=1 to n do a[i,3]:=a[i,3]+t-a[i,1];
    40      sort(1,n);l:=0;i:=0;
    41      while m>0 do
    42            begin
    43                 inc(i);
    44                 if (a[i,2]>=m) then
    45                    begin
    46                         l:=l+m*a[i,3];
    47                         m:=0;
    48                         break;
    49                    end;
    50                 l:=l+a[i,2]*a[i,3];
    51                 m:=m-a[i,2];
    52            end;
    53      writeln(l);
    54 end.   
  • 相关阅读:
    MsSql数据库存储过程加密解密
    Delete Exists
    SQL Server 2008数据库日志收缩
    MSSQL PIVOT 实现行列转置
    Oracle中将查询出的多条记录的某个字段拼接成一个字符串的方法
    oracle的分析函数over 及开窗函数
    Asprise-OCR的使用
    【整理】动态加载Web Services
    【转载】Python正则表达式指南
    Mac中PyCharm设置GitHub的步骤
  • 原文地址:https://www.cnblogs.com/HansBug/p/4298397.html
Copyright © 2011-2022 走看看