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:
  3. User: HansBug
  4. Language: Pascal
  5. Result: Accepted
  6. Time: ms
  7. Memory: kb
  8. ****************************************************************/
  9.  
  10. var
  11. i,j,k,l,m,n,t,v:longint;
  12. a:array[..,..] 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 ,];
  22. repeat
  23. while a[i,]<x do inc(i);
  24. while a[j,]>x do dec(j);
  25. if i<=j then
  26. begin
  27. swap(a[i,],a[j,]);
  28. swap(a[i,],a[j,]);
  29. swap(a[i,],a[j,]);
  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:= to n do readln(a[i,],a[i,],a[i,]);
  39. for i:= to n do a[i,]:=a[i,]+t-a[i,];
  40. sort(,n);l:=;i:=;
  41. while m> do
  42. begin
  43. inc(i);
  44. if (a[i,]>=m) then
  45. begin
  46. l:=l+m*a[i,];
  47. m:=;
  48. break;
  49. end;
  50. l:=l+a[i,]*a[i,];
  51. m:=m-a[i,];
  52. end;
  53. writeln(l);
  54. end.

2020: [Usaco2010 Jan]Buying Feed, II的更多相关文章

  1. 【BZOJ】2020: [Usaco2010 Jan]Buying Feed, II (dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2020 和背包差不多 同样滚动数组 f[j]表示当前位置j份食物的最小价值 f[j]=min(f[j- ...

  2. BZOJ 2020 [Usaco2010 Jan]Buying Feed,II:贪心【定义价值】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2020 题意: FJ开车去买K份食物. 如果他的车上有X份食物,每走一里就花费X元. FJ的 ...

  3. BZOJ2020: [Usaco2010 Jan]Buying Feed II

    [传送门:BZOJ2020] 简要题意: 约翰开车回家,遇到了双十一节,那么就顺路买点饲料吧.回家的路程一共有E 公里,这一路上会经过N 家商店,第i 家店里有Fi 吨饲料,售价为每吨Ci 元.约翰打 ...

  4. USACO Buying Feed, II

    洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II 洛谷传送门 JDOJ 2671: USACO 2010 Jan Silver 2.Buying Feed, II ...

  5. 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II

    洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...

  6. 【P2616】 【USACO10JAN】购买饲料II Buying Feed, II

    P2616 [USACO10JAN]购买饲料II Buying Feed, II 题目描述 Farmer John needs to travel to town to pick up K (1 &l ...

  7. BZOJ2059: [Usaco2010 Nov]Buying Feed 购买饲料

    数轴上n<=500个站可以买东西,每个站位置Xi,库存Fi,价格Ci,运东西价格是当前运载重量的平方乘距离,求买K<=10000个东西到达点E的最小代价. f[i,j]--到第i站不买第i ...

  8. ACM BUYING FEED

    BUYING FEED 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 Farmer John needs to travel to town to pick up ...

  9. BZOJ2021: [Usaco2010 Jan]Cheese Towers

    2021: [Usaco2010 Jan]Cheese Towers Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 184  Solved: 107[Su ...

随机推荐

  1. Windows 7 下 PHP 开发环境搭建(手动)

    Windows 7 下 PHP 开发环境搭建 1.说明 做开发的都知道一句话,就是“站在巨人的肩膀上”.确实现在打开浏览器随便一搜很多一键安装PHP环境的软件,比如wamp.xampp.AppServ ...

  2. EFCore扩展:IQueryable(linq)或sql执行的查询缓存与清理

    前言 上一篇讲述了执行sql和配置的一些功能,这篇说明IQueryable(linq)或执行sql的查询缓存与清理,包括扩展到将缓存存储到Redis中. 扩展类库源码: github:https:// ...

  3. 最近一年多我总结的常用mate标签-常用mate标签

    昨天开始上班  ,今天晚上不是太忙 ,来写篇博客了 meta元素共有三个可选属性(http-equiv.name和scheme)和一个必选属性(content),content定义与 http-equ ...

  4. WEB安全测试通常要考虑的测试点

    1问题:没有被验证的输入测试方法: 数据类型(字符串,整型,实数,等)允许的字符集 最小和最大的长度是否允许空输入参数是否是必须的重复是否允许数值范围特定的值(枚举型)特定的模式(正则表达式) 2问题 ...

  5. Cesium原理篇:glTF

    关键字:Cesium glTF WebGL技术 大纲: 1 glTF简介,这是一个什么东西,有哪些特点 2 Cesium如何加载,渲染glTF,逻辑结构和关键技术 3 个人总结,从glTF学习如何设计 ...

  6. Azure 基础:用 PowerShell 自动发布 CloudServices

    在软件的开发过程中,自动化的编译和部署能够带来很多的优势.下面我们聊聊如何自动发布云应用程序到 azure 上的 cloud services. 打包要发布的内容 首先使用 msbuild 编译 *. ...

  7. JavaScript中国象棋程序(4) - 极大极小搜索算法

    "JavaScript中国象棋程序" 这一系列教程将带你从头使用JavaScript编写一个中国象棋程序.这是教程的第4节. 这一系列共有9个部分: 0.JavaScript中国象 ...

  8. PHP 代码审计代码执行注入

    PHP 代码审计代码执行注入 所谓的代码执行注入就是 在php里面有些函数中输入的字符串参数会当做PHP代码执行. 如此的文章里面就大有文章可以探究了 一 常见的代码执行函数 Eval,assert, ...

  9. win8配置JDK

    有很多新手朋友对win7 和win8里的环境变量不是很熟悉,下面我整理了一下: 首先要说一下,win7里和win8配置方法是相同的,配置之前先去百度一下 JDK 然后找到自己电脑系统对应的jdk版本下 ...

  10. BZOJ 1019 :[SHOI2008]汉诺塔(递推)

    好吧蒟蒻还是看题解的 其实看到汉诺塔就该想到是递推了 设f[i][j]表示i个在j杆转移到另一个杆的次数 g[i][j]表示i个在j杆转移到那个杆上 可得 f[i][j]=f[i-1][j]+1+f[ ...