nyoj-248-buying feed
http://acm.nyist.net/JudgeOnline/problem.php?pid=248
BUYING FEED
- 描述
-
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 poundIt 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 pay1*1 = 1 cents.
When John travels from 4 to 5 heis 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.
- 输入
- The first line of input contains a number c giving the number of cases that follow
There are multi test cases ending with EOF.
Each case starts with a line containing three space-separated integers: K, E, and N
Then N lines follow :every line contains three space-separated integers: Xi Fi Ci - 输出
- For each case,Output A single integer that is the minimum cost for FJ to buy and transport the feed
- 样例输入
-
1
-
2 5 3
-
3 1 2
-
4 1 2
-
1 1 1
- 样例输出
-
7
解题思路:有C个样例,每个样例第一行有三个整数k, e, n,分别表示农夫要买的种子数量, 这条道路的长度, 何在该条路上的商店数量,接下来n行,每行三个数字xi, fi, ci,分别表示在xi位置的店家有fi的种子且单位重量的种子的运费为ci,让你求到达目的地需要花费最少多少运费, 可以先求出每种种子运到终点的运费之后贪心
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <string.h>
5
6 struct P{
7 int xi;
8 int fi;
9 int ci;
int cost;
}p[];
int cmp(const void *a, const void *b){
struct P *c = (struct P *)a;
struct P *d = (struct P *)b;
return c->cost - d->cost;
}
int main(){
int c, k, e, n;
int i;
int ans;
while(scanf("%d", &c) != EOF){
while(c--){
scanf("%d %d %d", &k, &e, &n);
for(i = ; i < n; i++){
scanf("%d %d %d", &p[i].xi, &p[i].fi, &p[i].ci);
//计算当前点1单位的种子运到重点需要花费多少?
p[i].cost = e - p[i].xi + p[i].ci;
}
qsort(p, n, sizeof(p[]), cmp);
// for(i = 0; i < n; i++){
// printf("%d %d %d %d\n", p[i].xi, p[i].fi, p[i].ci, p[i].cost);
// }
ans = i = ;
while(k >= p[i].fi){
ans += p[i].fi * p[i].cost;
k -= p[i].fi;
i++;
}
if(k > ){
ans += k * p[i].cost;
}
printf("%d\n", ans);
}
}
return ;
47 }
nyoj-248-buying feed的更多相关文章
- ACM BUYING FEED
BUYING FEED 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 Farmer John needs to travel to town to pick up ...
- 2020: [Usaco2010 Jan]Buying Feed, II
2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 220 Solved: 162[ ...
- BUYING FEED
Problem F: F BUYING FEED Description Farmer John needs to travel to town to pick up K (1 <= K < ...
- 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...
- USACO Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II 洛谷传送门 JDOJ 2671: USACO 2010 Jan Silver 2.Buying Feed, II ...
- 【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 ...
- [河南省ACM省赛-第三届] BUYING FEED (nyoj 248)
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> us ...
- 【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- ...
- Buying Feed, 2010 Nov (单调队列优化DP)
约翰开车回家,又准备顺路买点饲料了(咦?为啥要说"又"字?)回家的路程一共有 E 公里,这一路上会经过 K 家商店,第 i 家店里有 Fi 吨饲料,售价为每吨 Ci 元.约翰打算买 ...
- 【BZOJ2059】Buying Feed 购买饲料
题面 约翰开车来到镇上,他要带V吨饲料回家.如果他的车上有X吨饲料,每公里就要花费X^2元,开车D公里就需要D* X^2元.约翰可以从N家商店购买饲料,所有商店都在一个坐标轴上,第i家店的位置是Xi, ...
随机推荐
- beans.xml中的头部配置
Spring配置文件beans.xml头部配置解释 关于在beans.xml要使用哪些功能,官网上已经提供了每个功能说明和标准的头文件信息,当我们在开发使用时要哪些功能,都可以上官网去定位. http ...
- 洛谷CF895C Square Subsets(线性基)
洛谷传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 题意: 给你n个数,每个数<=70,问有多少个集合,满足集合中所有数相乘是个完全平方数(空集除外) 题解: 完全看不出这玩意儿和线性基有什 ...
- [Xcode 实际操作]二、视图与手势-(10)UITapGestureRecognizer手势之单击
目录:[Swift]Xcode实际操作 本文将演示使用视图的手势功能,完成视图的交互操作. import UIKit class ViewController: UIViewController { ...
- IT兄弟连 JavaWeb教程 Cookie和Session应用结合使用
一般对于不要求安全的非敏感数据,建议存储在Cookie中! 对于敏感的数据,占用空间较小的,建议存储在Session中! 对于敏感的,较大的数据,存数据库!
- Spark 学习(三) maven 编译spark 源码
spark 源码编译 scala 版本2.11.4 os:ubuntu 14.04 64位 memery 3G spark :1.1.0 下载源码后解压 1 准备环境,安装jdk和scala,具体参考 ...
- linux模拟http请求命令
Http请求指的是客户端向服务器的请求消息,Http请求主要分为get或post两种,在Linux系统下可以用curl和wget命令来模拟Http的请求.下面就来介绍一下Linux系统如何模拟Http ...
- 洛谷 P4503 [CTSC2014]企鹅QQ
暴力枚举不同的一位即可.. 主要是常数问题 1.统计答案时用sort速度快于用tr1/unordered_map,后者又快于map (tr1/unordered_map完全达不到理论复杂度上的O(1) ...
- ERP实施顾问,请找准自己的定位
最近给一些实施顾问做了培训.这些实施顾问都是我们渠道伙伴中具有较高提升潜质的顾问,期待做一次集中培训,他们能够在ERP项目实施上有所突破与提升,并能够为公司的ERP项目实施工作承担更多职责,分担更多压 ...
- MFC 创建UI线程
对于windows来说,所有的线程都是一样的,但MFC却把线程区分为两种:用户界面(UI)线程和工作者线程.用户界面线程具有消息循环而工作者线程没有.UI线程可以创建窗口并给这些窗口发送消息,工作者线 ...
- clearfix的运行机制和进化
话说为什么要把这个记下来,因为昨天去面试,问了clearfix的原理,当时脑子不清晰,回答得真是想要咬舌自尽.遂,决定,要搞清楚来龙去脉~~~(资料来自网上博主们,)http://www.aseoe. ...