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

相关文章

Jenkins--pipeline版本管理

为了提高脚本可维护性,更好的管理pipeline脚本,我们可以在项目配置中修改流水线定义,使用版本管理脚本,选择pipeline script from SCM: 我们看到现在SCM是无,因为还没有安装版本管理工具,先需要到插件管理中安装git。 安装后,在流水线设置的SCM中就能查看到Git: 在Repository URL中添加版本管理工具github或码云的仓库地址: 在Cred

Jenkins--pipeline认识及与RF文件的结合应用

什么是pipeline? Pipeline,就是可运行在Jenkins上的工作流框架,将原本独立运行的单个或多个节点任务连接起来,实现单个任务难以完成的复杂流程编排与可视化。 为什么要使用pipeline? 1.流程可视化显示 2.可自定义流程任务 3.所有步骤代码化实现 如何使用pipeline 首先需要安装pipeline插件: 流水线有声明式和脚本式的流水线语法 流水线结构介绍 Node:

使用Azure Devops Pipeline将Docker应用部署到你的Raspberry Pi上

文章目录 1. 添加树莓派到 Agent Pool1.1 添加pool1.2 添加agent 2. 将树莓派添加到 Deployment Pool2.1 添加pool2.2 添加target 3. 添加编译流水线3.1 添加编译命令3.2 配置触发器 4. 添加发布流水线4.1 添加命令行4.2 配置artifact和触发器 5. 完成 1. 添加树莓派到 Agent Pool

Netty源码解析3-Pipeline

请戳GitHub原文: https://github.com/wangzhiwubigdata/God-Of-BigData Channel实现概览 在Netty里,Channel是通讯的载体,而ChannelHandler负责Channel中的逻辑处理。 那么ChannelPipeline是什么呢?我觉得可以理解为ChannelHandler的容器:一个Channel包含一个Chan

【人工智能】Transformers之Pipeline(十五):总结(summarization)

​​​​​​​ 目录 一、引言  二、总结(summarization) 2.1 概述 2.2 BERT与GPT的结合—BART 2.3 应用场景​​​​​​​ 2.4 pipeline参数 2.4.1 pipeline对象实例化参数 2.4.2 pipeline对象使用参数 ​​​​​​​ 2.4.3 pipeline返回参数 ​​​​​​​​​​​​​​ 2.5 pipe

读懂以太坊源码(2)-重要概念Gas

在以太坊中,gasLimit、gasUsed和gasPrice是三个重要的概念,它们之间有特定的含义和关系。 一、含义 gasLimit: 含义:每个区块或每笔交易都有一个 gas 限制。对于一个区块来说,gasLimit是该区块中所有交易可以消耗的最大 gas 总量。对于一笔交易,发送者可以设置该交易的 gas 限制,即愿意为这笔交易支付的最大 gas 量。作用:它的存在是为了防止无限

区块链 以太坊 代码gas消耗多少

https://blog.csdn.net/fpcc/article/details/82929982   以太坊黄皮书 https://ethereum.github.io/yellowpaper/paper.pdf

NLP-文本摘要:利用预训练模型进行文本摘要任务【transformers:pipeline、T5、BART、Pegasus】

一、pipeline 可以使用pipeline快速实现文本摘要 from transformers import pipelinesummarizer = pipeline(task="summarization", model='t5-small')text = """summarize: (CNN)For the second time during his papacy, Pope Fr

jenkins pipeline文件使用码云保存

基本步骤如下: 1.在码云新建个空的代码仓库 2.如果使用blue ocean工具编写则将码云仓库地址复制过去,依据编辑器配置即可,保存成功后,会在码云仓库保存编写好的Jenkinsfile文件 3.如果不是使用blue ocean编写的,用其它工具编写,则在Jenkins创建流水线后配置仓库地址即可,如: 对应仓库如下: 说明:pipeline默认的流水线文件名为Jenkinsfile,

Jenkins pipeline:pipeline 使用之语法详解

Jenkins pipeline:pipeline 使用之语法详解