ZOJ 3699 Dakar Rally(贪心)

别再问“这游戏啥引擎做的”了,手把手教你用SteamDB一键查询(附实战案例) 本文详细介绍了如何使用SteamDB一键查询游戏引擎信息,包括Unity 3D、Unreal Engine等热门引擎的识别方法。通过实战案例和高级查询技巧,帮助玩家快速获取游戏技术底细,优化游戏体验和兼容性分析。 阅读详情

题意  路上有 n 个加油站  每个加油站的价格可能不同  你的油箱容积为 v  问从起点开车到终点加油至少用多少钱

贪心  每次都让油箱里面便宜的油最多就行了   在每个站点 i 有两种情况

1.  i 点把油加满跑完都没有更便宜的  那么在 i 点肯定要加满  然后开到 i+1 点去

2.  i 点把油加满能跑到第一个比 i 点更便宜的 j 点或者到了终点 j   那么只用把油加到能到 j 点  然后直接开到 j 点

然后把每个点加油用的钱加起来就行了

#include <cstdio>
using namespace std;
const int N = 100005;
typedef long long ll;
ll len[N], cost[N], pri[N], v;

int main()
{
    int T, n;
    scanf("%d", &T);

    while(T--)
    {
        scanf("%d%lld", &n, &v);
        int flag = 0;

        for(int i = 0; i < n; i++)
        {
            scanf("%lld%lld%lld", &len[i], &cost[i], &pri[i]);
            if(len[i] * cost[i] > v) flag = 1;
        }

        if(flag)
        {
            puts("Impossible");
            continue;
        }

        int i = 0, j;
        ll r = 0, ans = 0, t;                 //r记录到i点还剩多少油
        while(i < n)
        {
            j = i + 1, t = len[i] * cost[i];  //t记录到下一个便宜的点用了多少油

            //往前走直到找到一个更便宜的站j  或者油箱跑完
            while( j < n && pri[j] >= pri[i] && v - t >= cost[j] * len[j])
            {
                t += len[j] * cost[j];
                ++j;
            }


            if( j >= n || pri[j] < pri[i])  //j点油第一个比i点便宜  加到能到j
            {
                if(r > t)  r -= t;
                else
                {
                    ans += (t - r)  * pri[i];
                    r = 0;
                }
                i = j;
            }

            else  //油跑完都没更便宜的 加满 到下一站
            {
                ans +=  (v - r) * pri[i];
                r = v - len[i] * cost[i];
                i++;
            }
        }

        printf("%lld\n", ans);
    }

    return 0;
}
Dakar Rally

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Description

The Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The off-road endurance race consists of a series of routes. In different routes, the competitors cross dunes, mud, camel grass, rocks, erg and so on.

Because of the various circumstances, the mileages consume of the car and the prices of gas vary from each other. Please help the competitors to minimize their payment on gas.

Assume that the car begins with an empty tank and each gas station has infinite gas. The racers need to finish all the routes in order as the test case descripts.

Input

There are multiple test cases. The first line of input contains an integer T (T ≤ 50) indicating the number of test cases. Then T test cases follow.

The first line of each case contains two integers: n -- amount of routes in the race; capacity -- the capacity of the tank.

The following n lines contain three integers each: mileagei -- the mileage of the ith route; consumei -- the mileage consume of the car in the ith route , which means the number of gas unit the car consumes in 1 mile; pricei -- the price of unit gas in the gas station which locates at the beginning of the ith route.

All integers are positive and no more than 105.

Output

For each test case, print the minimal cost to finish all of the n routes. If it's impossible, print "Impossible" (without the quotes).

Sample Input
2
2 30
5 6 9
4 7 10
2 30
5 6 9
4 8 10
Sample Output
550
Impossible


PIC单片机应用开发实践教程(二): 新建工程 File---New ProjectMicrochip Embedded --- Standalone Project 选择所用MCU对应型号 点击 Finish 后,工程就建好了 至止,我们的一个新工程就建完成了! 阅读详情

相关推荐

计算pi小数点后10000位

数据结构课上,老师让我们计算一下pi的10000位,复习一下面向对象。 First Try:定义一个高精度类hp(high precision),实现加减乘除,输入输出,然后随便找一个公式,比如Wallis公式,全都用hp进行计算。 现实是:大数乘大数或者大数除大数,实在是太慢了。而且Wallis公式收敛太慢。 Second Try先找到一个收敛较快的公司:BBP公式,观察公式发现,...

我的技术人生 7395

zoj3699 Dakar Rally (单调队列+贪心)

传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3699 ime Limit: 2 Seconds      Memory Limit: 65536 KB Description The Dakar Rally is an annual Dakar Series rally raid type of o

超级菜鸟ZiP的小窝 928

Java8动态生成SFunction:基于字段名的Lambda表达式实践

本文深入探讨了在Java8中如何基于字段名动态生成SFunction,以解决MyBatis Plus的LambdaQueryWrapper在动态查询场景下的局限性。通过核心原理LambdaMetafactory的解析和手把手的代码实现,展示了如何将字符串字段名转换为类型安全的Lambda表达式,从而实现真正动态、类型安全的查询条件构建与通用数据处理,显著提升代码的灵活性与安全性。

sss66的博客 953

ZOJ 3699 Dakar Rally(贪心算法)

Dakar Rally Time Limit: 2 Seconds Memory Limit: 65536 KB DescriptionThe Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The of

linlinsong—ACM界蒟水! 535

ESP32+MAX7219二进制时钟设计与嵌入式时间映射实践

二进制时钟是嵌入式系统中数据表示与物理呈现深度耦合的典型范例,其核心在于将时间语义(年月日时分秒)解构为比特位,并通过LED点阵的空间权重布局实现直观识别。该设计依托RTC模块提供时间基准,依赖SPI协议完成微控制器与专用驱动芯片(如MAX7219)的可靠通信,涉及寄存器级配置、位图坐标变换、软硬件时序对齐等关键原理。技术价值体现在低资源占用下的高可读性人机交互,适用于教学演示、极客项目及嵌入式UI原型开发。本文聚焦ESP32平台在MicroPython环境下,结合MAX7219驱动8×8点阵实现高可靠性二

weixin_42160645的博客 301

山东大学软件工程应用与实践——GMSSL开源库(六)——SM9密钥交换协议

2021SC@SDUSC 文章目录基本概念符号及辅助算法SM9密钥交换协议 基本概念 1976年,Diffie和Hellman在其题为《密码学的新方向》的论文中首次给出了公钥密码学的定义,并提出了Diffie-Hellman密钥交换算法。该算法解决了对称密码体制中的密钥分发问题,使得通信双方可以通过公开信道安全地交换共享密钥。 使用SM9通信的双方通过对方的标识和自身的私钥,经过两次或者可选的三次信息传递过程,计算获取一个由双方共同决定的共享秘密密钥。该密钥可以作为对称密码算法的会话密钥,其中可选步骤用来实

m0_51588039的博客 1988

ZOJ - 3699 Dakar Rally (单调队列,贪心)

题目:为赛车手安排个加油计划,使其骑完所有路线所耗费最少的由钱,当然如果中途因为油不够就输出Impossible表示完成不了。第一行T表示样例个数,紧接一行N,M,N表示有这么多条路,M代表车子油箱的容纳量。以后每行分别有三个数,表示改路线长度Len,需要消耗的油量gas,该路段加油站的油价price.求出走完所有路线最低消费。 首先如果油箱容量比Len*gas还要小的话直接输出 Impossi...

XFire的博客 337

基于分位数回归的静态CoVaR计算 案例与代码

原文链接:https://bbs.pinggu.org/thread-7925441-1-1.html 一、静态CoVaR模型介绍 二、资料简介 实现对相关期刊论文进行论文重现,解决实证分析中的技术操作问题。里面包含了每一步详细的步骤,可以方便的利用这个手册解决大部分利用分位数回归计算静态CoVaR的论文的模型实现问题。即从数据下载到模型实现一整条操作步骤。 关键词:【分位数回归】【Co...

ChenQihome9的博客 7506

ZOJ 3699 Dakar Rally(贪心)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3699 Dakar Rally Time Limit: 2 Seconds     Memory Limit:65536 KB Description The Dakar Rally is an annual Dakar Series rally raid

hellohelloC的博客 1001

Coze智能体开发:扣子空间制作PPT功能

扣子空间内置了丰富的场景模板,涵盖人文历史、学术分享、研究报告、数据分析等场景,可以满足不同用户的需求。 你只需输入与制作 PPT 相关的提示词,Agent 就能基于这些提示词展示思考的过程,并自动生成完整的 PPT。

王国平的博客 2053

【OpenAI】Python:(1) 基于 Gym-CarRacing 的自动驾驶项目 | 前置知识介绍 | 项目环境准备 | 手把手带你一步步实现

本篇是关于多伦多大学自动驾驶专业项目 Gym-CarRacing 的博客。GYM-Box2D CarRacing 是一种在 OpenAI Gym 平台上开发和比较强化学习算法的模拟环境。它是流行的 Box2D 物理引擎的一个版本,经过修改以支持模拟汽车在赛道上行驶的物理过程。由于内容比较多所以分多次更新,本篇是关于前置知识介绍,以及项目环境准备的。

有道无术, 术尚可求。有术无道, 止于术。 5053

Dakar Rally ZOJ - 3699(思维+贪心)

Description TheDakar Rallyis an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The off-road endurance race consists of a series of routes. In diff...

why932346109的博客 272

二维光子晶体禁带的遗传优化算法实现

二维光子晶体禁带的遗传优化算法MATLAB源代码 光子晶体中因周期性结构而存在的频率禁带称为光子禁带,光子禁带的存在是光子晶体具有广泛应用前景的重要原因。 禁带越大,可控光的频带也越宽,因此如何设计合适的晶体结构以获得大的光子禁带一直是研究和应用的重点与热点。 给大家讲解在平面波展开法的基础上,使用遗传算法寻找具有最大光子禁带的二维光子晶体结构。 %-------------------------------------------------------------------------- % Ph

m0_53407570的博客 583

Dakar Rally ZOJ - 3699(贪心)

Dakar Rally ZOJ - 3699(贪心)题目描述题目链接参考题解题意思路代码 题目描述  Description  The Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The off-road end...

Steve·Curcy 439

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

ZOJ 3699 Dakar Rally(贪心)

  这是一道贪心题,他的贪心思想很容易想明白,我们保证油箱里的油始终是最便宜的我们最后的花费就能是最少的.实现方法就是:比如现在在i点,我们看邮箱满载能最远到达哪里,不妨设最远到达j,(j >= i + 1),注意此处的达到,只是指能够到达这个路段的开头位置,并不是走完这段路...所以我们到达j点会有一个leave剩余,leave >= 0,但是在i 和 j点之间我们只需要到达第一个油...

weixin_30764883的博客 110

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

zoj 3699 Dakar Rally

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3699 题目大意: 有n段路,从左到右编号1~n,只有通过一段路才会耗油,每段路的最左边有一个加油站,第i段路的加油站的邮费pi、长度是mi、单位耗油ci。 给定邮箱容量cap,问从左到右通过n段路的最小耗油量。 所有正整数不超过10^5.

Go.To.AC的专栏 1513

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

ZOJ 3699 Dakar Rally

Description The Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The off-road endurance race consists of a series of routes. In diff

LSC_333的博客 411

ZOJ 3699 Dakar Rally 解题报告

题意:给油箱容量,n个有顺序的点,给出从当前点到下一个点的距离,单位耗油量,汽油的单价。每个站都能加不超过油箱容量的油。求到终点的最小花费。 解法:本着贪心的原则,应该尽量在便宜的地方多加油。 所以模拟汽车行驶的过程中,在比当前位置汽油便宜的站能加要尽量加满(如果之后发现不是最优的就减去),并记录每一站剩余的可用油量,和到当前站油箱中剩余的汽油(因为要保证不超过油箱容量)。而花费是统计从当前站

Tri_integral的专栏 1268

ZOJ-3699 Dakar Rally 单调队列

题意:比赛的时候想了各种的贪心方案,最后还是没有把这题搞出来......废话不多说,题目给定了一条条给定了顺序的路径,这些路径是后面要一一走过的,每条路径有一个长度,单位长度消耗汽油的量以及该条公路上加油站的汽油单价。告诉你路径条数N,油箱容积K,问如何安排加油是的行走完所有路径的花费最少。 解法:该题有一个很巧妙的解法就是每到一个油站都加满油箱,队列里面保留了走过前面路径后保留的最便宜的油,每...

weixin_33724570的博客 106

zoj 3699 单调队列

Dakar Rally Time Limit: 2 Seconds      Memory Limit: 65536 KB Description The Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organiz

写东西的地方 756

Day5:ZOJ 3699(贪心) + 第二届省赛H题(优先队列)

ZOJ 3699 Description The Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The off-road endurance race consists of a series of route...

qq_29904713的博客 284
上一篇: POJ 2823 Sliding Window(单调队列)
下一篇: ZOJ 3761 Easy billiards (DFS性质)
virgoDd
博客等级 码龄12年 95粉丝 246原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值