C. Gas Pipeline(1207C)

2024-04-16 02:58
文章标签 pipeline gas 1207c

本文主要是介绍C. Gas Pipeline(1207C),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

C. Gas Pipeline
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are responsible for installing a gas pipeline along a road. Let’s consider the road (for simplicity) as a segment [0,?] on ?? axis. The road can have several crossroads, but for simplicity, we’ll denote each crossroad as an interval (?,?+1) with integer ?. So we can represent the road as a binary string consisting of ? characters, where character 0 means that current interval doesn’t contain a crossroad, and 1 means that there is a crossroad.

Usually, we can install the pipeline along the road on height of 1 unit with supporting pillars in each integer point (so, if we are responsible for [0,?] road, we must install ?+1 pillars). But on crossroads we should lift the pipeline up to the height 2, so the pipeline won’t obstruct the way for cars.

We can do so inserting several zig-zag-like lines. Each zig-zag can be represented as a segment [?,?+1] with integer ? consisting of three parts: 0.5 units of horizontal pipe + 1 unit of vertical pipe + 0.5 of horizontal. Note that if pipeline is currently on height 2, the pillars that support it should also have length equal to 2 units.

Each unit of gas pipeline costs us ? bourles, and each unit of pillar — ? bourles. So, it’s not always optimal to make the whole pipeline on the height 2. Find the shape of the pipeline with minimum possible cost and calculate that cost.

Note that you must start and finish the pipeline on height 1 and, also, it’s guaranteed that the first and last characters of the input string are equal to 0.

Input
The fist line contains one integer ? (1≤?≤100) — the number of queries. Next 2⋅? lines contain independent queries — one query per two lines.

The first line contains three integers ?, ?, ? (2≤?≤2⋅105, 1≤?≤108, 1≤?≤108) — the length of the road, the cost of one unit of the pipeline and the cost of one unit of the pillar, respectively.

The second line contains binary string ? (|?|=?, ??∈{0,1}, ?1=??=0) — the description of the road.

It’s guaranteed that the total length of all strings ? doesn’t exceed 2⋅105.

Output
Print ? integers — one per query. For each query print the minimum possible cost of the constructed pipeline.

Example
inputCopy
4
8 2 5
00110010
8 1 1
00110010
9 100000000 100000000
010101010
2 5 1
00
outputCopy
94
25
2900000000
13
Note
The optimal pipeline for the first query is shown at the picture above.

The optimal pipeline for the second query is pictured below:

The optimal (and the only possible) pipeline for the third query is shown below:

The optimal pipeline for the fourth query is shown below:

题意: 二进制01串。为1代表这个地方得是高度为2的柱子,为0代表可以为高度为1或者2的柱子。起点和终点柱子高度都为1。同时横向走的时候需要管道。柱子的单位花费是b,管道的单位花费是a。问怎么安排使得花费最小

思路: 这种模拟题细节很多,关键就在于:思路一定要清晰。机房几个大佬卡在这里,都是因为一些小细节:循环边界问题,long long问题,变量毒瘤问题。

n个点的话,会有n+1个柱子,有柱子的地方就标上号。二进制为1的话,1这个格子代表的两个点都得是高柱子。高柱子中间的部分,就是贪心的地方。

首先确定基础花费:n个管道:na,n+1个低柱子:nb,2个转折管道:2a(全是0的话没有)。中间可以高柱子的部分,假设长度为x,选择高柱子,额外花费为xb。选择低柱子,花费为2*a。选择最小的就可以了。

注意:起点终点一定是低柱子!!

#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstring>using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 7;
#define INF 0x3f3f3f3fll maze[maxn];
char str[maxn];
int main()
{ll T;scanf("%lld",&T);while(T--){memset(maze,0,sizeof(maze));ll n,a,b;scanf("%lld%lld%lld",&n,&a,&b);scanf("%s",str);ll sta = INF,en = 0;for(ll i = 0;i < n;i++){if(str[i] == '1'){maze[i] = 1;maze[i+1] = 1;sta = min(sta,i);en = max(en,i + 1);}}ll num0 = 0,num1 = 0;ll ans = 0;for(ll i = sta;i <= en;i++){if(maze[i] == 0)num0++;else{num1++;ll tmp = 0;tmp = min(num0 * b,2 * a);ans += tmp;num0 = 0;}}ans += 2 * a + n * a + (n + 1) * b + num1 * b;if(sta == INF && en == 0)ans -= 2 * a;printf("%lld\n",ans);}return 0;
}

这篇关于C. Gas Pipeline(1207C)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/907629

相关文章

Pipeline知识小记

在scikit-learn(通常缩写为sklearn)中,Pipeline是一个非常重要的工具,它允许你将多个数据转换步骤(如特征选择、缩放等)和估计器(如分类器、回归器等)组合成一个单一的估计器对象。这种组合使得数据预处理和模型训练变得更加简洁和高效。 使用Pipeline的主要好处包括: 简化工作流:你可以在一个对象中定义整个数据处理和建模流程。避免数据泄露:在交叉验证或其他评估过程中,P

BEVM如何实现兼容OP Stack以WBTC为Gas的创新解决方案?

区块链技术在经历了十多年的不断发展后,也来到了技术爆发期,BEVM作为在比特币生态深耕超过7年的团队,在这一领域一直保持着卓越的创新能力和前瞻性思维。 近期在内部技术研讨和实践中,BEVM团队计划基于OPtimism团队的OP Stack和Starkware 的Madara模块,来继承以太坊网络的安全性,实现BEVM与以太坊网络之间的无缝连接。目前,BEVM团队正基于OP Stack开发一条服务

.NET客户端实现Redis中的管道(PipeLine)与事物(Transactions)(八)

序言 Redis中的管道(PipeLine)特性:简述一下就是,Redis如何从客户端一次发送多个命令,服务端到客户端如何一次性响应多个命令。 Redis使用的是客户端-服务器模型和请求/响应协议的TCP服务器,这就意味着一个请求要有以下步骤才能完成:1、客户端向服务器发送查询命令,然后通常以阻塞的方式等待服务器相应。2、服务器处理查询命令,并将相应发送回客户端。这样便会通过网络连接,如

【Linux】Jenkins Pipeline流水线详解及基于Jenkins流水线实现自动更新项目(实战)

👨‍🎓博主简介   🏅CSDN博客专家   🏅云计算领域优质创作者   🏅华为云开发者社区专家博主   🏅阿里云开发者社区专家博主 💊交流社区:运维交流社区 欢迎大家的加入! 🐋 希望大家多多支持,我们一起进步!😄 🎉如果文章对你有帮助的话,欢迎 点赞 👍🏻 评论 💬 收藏 ⭐️ 加关注+💗 文章目录 一、Pipeline 流水线的简介1.1 什么

以MixtralForCausalLM为例,演示如何不依赖框架实现pipeline并行

以MixtralForCausalLM为例,演示如何不依赖框架实现pipeline并行 1.创建Mixtral-8x7B配置文件2.测试代码 本文以MixtralForCausalLM为例,演示如何不依赖框架实现pipeline并行 主要步骤: 1.分析网络结构,确定拆分规则: 第一部分:embed_tokens+MixtralDecoderLayer[:8] 第二部分:Mixt

AzureDataFactory 在不同的订阅间迁移Pipeline

前面的博文中的POC是客户向微软申请的试用环境,POC结束客户也购买了Azure订阅,需要复用试用环境中的Pipeline,此时就需要将Pipeline进行迁移。         目之所及有两种方式,第一种是通过导入导出模版,选择需要迁移的Pipeline,导出模版,导出后是一个zip文件      然后再到你的目标环境中选择导入模版,选择刚刚下载的zip文件

docker镜像拉取K8s的calico,Pod报错Init:ImagePullBackOff及kubekey生成离线包报错error: Pipeline[ArtifactExportpipe的解决

配置k8s集群出现问题 起初以为是版本问题,最后比对了一下发现没有问题。使用 kubectl describe calico-node-mg9xh -n kube-system命令查看发现docker pull 镜像失败,但是docker国内镜像源早就配置过了。 猜测Docker的缓存可能会导致拉取镜像失败。尝试删除Docker的缓存,然后重新拉取镜像。但还是失败,网上查了整整一天的时间去折腾

区块链中的gas与转账收款相关概念

区块链是一个经济系统 计算与存储系统都是稀缺的,区块链的工作需要消耗资源共识、trustless需要矿工的工作,而矿工需要激励Transaction的执行有成本(gas),gas费成为矿工的奖励ether是这个经济生态系统的通行货币 关心的问题 合约执行中的经济成本,即gas问题智能合约实现货币的流通,即转账收款功能 货币转换单位 合约持有ether address.balanc

Redis高级特性和应用:慢查询、Pipeline、事务、Lua

Redis提供了许多高级特性,可以帮助优化和管理系统性能。本文将介绍Redis的慢查询、Pipeline、事务和Lua脚本的使用及其相关配置。 Redis的慢查询 慢查询日志是开发和运维人员定位系统慢操作的重要工具。Redis也提供了类似的功能,通过记录超过预设阀值的命令执行时间来帮助诊断性能问题。 Redis客户端执行命令的过程 Redis客户端执行一条命令的过程可以分为以下四个部分:

Pipeline流水线组件

文章目录 1、新建pipeline流水线2、定义处理器3、定义处理器上下文4、pipeline流水线实现5、处理器抽象类实现6、pipeline流水线构建者7、具体处理器实现8、流水线测试9、运行结果 1、新建pipeline流水线 package com.summer.toolkit.model.chain;import java.util.List;import java