BUYING FEED (第三届省赛)

BUYING FEED

 

(英文题!!!!   为那些跟我一样acmer翻译一下吧  是实话 看不懂题真的很烦人     以上都是废话, 下面解释

英文题不出意外还是队友写的, 题意是第一行输入  要买的量k   要走的总长度e   店铺的数量n ;    然后就是每家店铺距离起点的距离    存货量    成本   。

ps : 将一单位的物品移动一个单位的距离要花费1磅运费;

求  需要花费的最小的成本;

(这道题的解题思路在于按照  将每家店铺以单位的物品运到终点所需要的成本 排序, 然后从成本低的开始购买直到量够为止

 

 

题目描述

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 John 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.
Farmer John 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 Farmer John has to pay to buy and transport the K pounds of feed? Farmer John knows there is a solution.
Consider a sample where Farmer John 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 John 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 John 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 John 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.

 

输入

Line 1: Three space-separated integers: K, E, and N
Lines 2…N+1: Line i+1 contains three space-separated integers: Xi Fi Ci

 

输出

A single integer that is the minimum cost for FJ to buy and transport the feed

 

样例输入

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

样例输出

7





 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 #include<ctype.h>
 5 #define N 1010
 6 #define max(a, b)(a > b ? a : b)
 7  
 8 typedef struct node
 9 {
10     int d, t, p;
11     int money;
12 } node;
13  
14 int cmp(const void *a, const void *b)
15 {
16     node *s1 = (node *)a, *s2 = (node *)b;
17     return s1->money - s2->money;
18 }
19 int main()
20 {
21     node node[N];
22     int k, m, n, sp, st, i;
23     while(scanf("%d%d%d", &k, &m, &n) != EOF)
24     {
25         st = sp = 0;
26         for(i = 0 ; i < n ; i++)
27         {
28             scanf("%d%d%d", &node[i].d, &node[i].t, &node[i].p);
29             node[i].money = (m-node[i].d)+node[i].p;
30         }
31         qsort(node, n, sizeof(node[0]), cmp);
32          for(i = 0; i<n; i++)
33          {
34              if(st < k)
35              {
36                 if(node[i].t>k-st  || node[i].t == k-st)
37                 {
38                     sp += (k-st)*node[i].money;
39                     break;
40                 }
41                 else
42                 {
43                     st += node[i].t;
44                     sp += node[i].t*node[i].money;
45                 }
46              }
47          }
48         printf("%d\n", sp);
49     }
50     return 0;
51 }

 

 

最后再说一句 由于能力有限 有两道不会写的没有发代码和题解;

 

 

————————END

 

posted on 2015-05-04 17:19  梦林``ysl  阅读(180)  评论(0编辑  收藏  举报

导航