CF1040A Palindrome Dance

Vue项目实战:海康WebControl插件从安装到预览功能全流程(附RSA加密避坑指南) 本文详细介绍了在Vue项目中集成海康威视WebControl插件的全流程,从环境准备、插件部署到核心功能实现。重点解析了使用JS_RequestInterface获取RSA公钥并进行加密参数初始化的关键步骤与常见避坑指南,帮助开发者高效完成监控视频预览功能的开发与调试。 阅读详情

原题链接:http://codeforces.com/contest/1040/problem/A

Palindrome Dance

A group of n n n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they’ve studied their dancing moves and can’t change positions. For some of them, a white dancing suit is already bought, for some of them — a black one, and for the rest the suit will be bought in the future.

On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer’s suit is the same as the color of the rightmost dancer’s suit, the 2nd left is the same as 2nd right, and so on.

The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it’s possible, what’s the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.

Input

The first line contains three integers n n n, a a a, and b ( 1 ≤ n ≤ 20 , 1 ≤ a , b ≤ 100 ) b (1≤n≤20, 1≤a,b≤100) b(1≤n≤20,1≤a,b≤100) — the number of dancers, the cost of a white suit, and the cost of a black suit.

The next line contains n n n numbers c i , i c_i, i ci​,i-th of which denotes the color of the suit of the i i i-th dancer. Number 0 0 0 denotes the white color, 1 1 1 — the black color, and 2 2 2 denotes that a suit for this dancer is still to be bought.

Output

If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.

Examples
input

5 100 1
0 1 2 1 2

output

101

input

3 10 12
1 2 0

output

-1

input

3 12 1
0 1 0

output

0

Note

In the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.

In the second sample, the leftmost dancer’s suit already differs from the rightmost dancer’s suit so there is no way to obtain the desired coloring.

In the third sample, all suits are already bought and their colors form a palindrome.

题解

因此题过水,题解被折叠。

代码
#include<bits/stdc++.h>
using namespace std;
const int M=25;
int n,a,b,ans,x1[M],x2[M];
void in(){scanf("%d%d%d",&n,&a,&b);for(int i=1;i<=n;++i)scanf("%d",&x1[i]),x2[n-i+1]=x1[i];}
void ac()
{
	for(int i=1;i<=n;++i)
	if(x1[i]==2)ans+=(x2[i]==2?min(a,b):(x2[i]?b:a));
	else if(x1[i]!=x2[i]&&x2[i]!=2)puts("-1"),exit(0);
	printf("%d",ans);
}
int main(){in();ac();}
【2026-Spark实验一-Windows中安装Spark环境】 本文详细介绍了在Windows系统中配置Spark 3.5.8开发环境的完整流程。主要内容包括:安装JDK 8并配置环境变量,下载并解压Spark 3.5.8预编译版,设置SPARK_HOME系统变量,配置Hadoop的winutils工具解决Windows兼容性问题。通过spark-shell和SparkPi示例程序验证环境配置成功,确保Spark能够正常运行分布式计算任务。文中特别强调了路径命名规范、环境变量设置顺序等关键细节,提供了完整的配置截图和验证方法,帮助开发者快速搭建稳定的Spark学习环境。 阅读详情

相关推荐

VsCode安装和配置c/c++环境(超完整,小白专用)

1. vsCode配置C/C++环境 1. vsCode下载和安装 1. 下载Microsoft vsCode [vsCode在这里插入图片描述官网下载: https://code.visualstudio.com/ 2. 安装vsCode 3. 下载中文插件 我这边已经下载过,刚卸载但是没有重启编译器,所以界面显示了中文 2. MinGW编译器下载和配置 1. 下载MinGW 在线安装——下载MinGW-W64-install.exe(速度慢) 下载压缩包——×86_64-posix-

黄化的多多 60万+

codeforces 1040a (回文数的舞蹈)

原题链接 A. Palindrome Dance A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they’ve studied their dancing moves and can’t change positions. For...

starlet_kiss的博客 381

VS2022错误列表高效处理:从复制到Excel表格的完整指南

本文详细介绍了在Visual Studio 2022中高效处理错误列表的实用技巧,重点讲解了如何将错误信息一键复制并粘贴到Excel表格中。通过基础操作、自定义视图、筛选功能及常见问题解决方案,帮助开发者将杂乱的编译错误整理成清晰、可排序、可筛选的数据表,极大提升了团队协作、错误分析和项目管理的效率。

weixin_28837817的博客 358

UVA Palindromes(模拟)

Palindromes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same for

叶孤心的专栏 746

淘晶驰串口屏自定义协议实战:5分钟搞定苹果时钟通信(附完整代码)

本文详细介绍了如何使用淘晶驰串口屏自定义通信协议快速实现苹果风格时钟的通信功能。通过精简的协议设计和完整的代码示例,开发者可以在5分钟内完成从硬件连接到软件实现的整个过程,适用于嵌入式开发中的高效通信需求。

weixin_29184371的博客 323

stata 代码实现熵值法计算 含常见问题解答

2.标准化①正向指标②负向指标。

m0_74825360的博客 1217

Palindrome Dance

Palindrome Dance A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they’ve studied their dancing moves and can’t change positions. For some of them, a white dancing suit is already bought, for some of

Hello_wcrd的博客 206

【C语言趣味教程】(0) 专栏介绍

这是一套C 语言趣味教学专栏,目前正在火热连载中,欢迎猛戳订阅!本专栏保证篇篇精品,继续保持本人一贯的幽默式写作风格,当然,在有趣的同时也同样会保证文章的质量,旨在能够产出"有趣的干货" !本系列教程不管是零基础还是有基础的读者都可以阅读,可以先看看目录!标题前带星号 (*) 的部分不建议初学者阅读,因为内容难免会超出当前章节的知识点,面向的是对 C 语言有一定基础或已经学过

有道无术, 术尚可求。有术无道, 止于术。 2万+

1040A Palindrome Dance

点击传送门查看题目:传送门 题意:有n个人,要每个穿西服,有三种情况,一种是穿了白色0西装, 一种是穿了黑色的1西装,还有一种没有穿用2表示, 现在需要给没有穿的人买西装,让他们颜色形成回文串,如果不可能形成就输出-1。 题解:模拟  两边向中间判断,如果是不相等,并且没有2,就输出-1,如果两个相等都为2,ans就加花费小的*2,如果相等不为2,就跳过,如果不想等,把2变成对面那个对应的颜...

memory_qianxiao的博客 550

北斗导航 | 卫星信号捕获跟踪原理解析

卫星信号的捕获与跟踪是导航接收机的"眼睛",其性能直接决定定位精度、动态适应性和抗干扰能力。随着北斗三号全球组网完成,新一代接收机正朝着。两大核心阶段,二者共同构成定位的基础。调制,频谱主瓣宽度达4.092MHz,较传统BPSK调制抗干扰能力提升3dB[38]。的目标持续演进,在自动驾驶、精密农业等领域展现出巨大应用潜力。二维空间中搜索峰值相关能量[4]。卫星导航接收机对信号的处理可分为。北斗三号B1C/B2a信号采用。北斗三号新增的B1C信号采用。

尘世冰封的专栏 773

基于 ESP32 的智慧图书馆图书定位与借阅管理系统

本文设计的基于 ESP32 的智慧图书馆图书定位与借阅管理系统,以低成本、模块化、易部署为核心优势,融合 UWB 精准定位、RFID 自动识别、WiFi 无线通信技术,解决了传统图书馆的痛点问题。

weixin_42300449的博客 99

1136. A Delayed Palindrome (20) 大数模拟

1136. A Delayed Palindrome (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Consider a positive integer N written

zhangchaosd的博客 1203

Challenge 4 - OSCP A

在c盘下发现一个windows.old,在里面可以找到SYSTEM和SAM文件,下载到本地,利用samdump2解密发现没解出来,再来试试pwdump.py(https://github.com/CiscoCXSecurity/creddump7)得到压缩包密码bludecode,解压之后发现一个比较特殊的文件configuration.php,里面有两个类似密码的字符串。登录之后在/opt/backups/下发现几个特殊文件,其中sitebackup3.zip是个正常的压缩包。但是这个压缩包是有密码的。

羽的博客 5782

Codeforces1040A Palindrome Dance

优快云失踪人口回归了,毕竟还是要准备SOI的,从今天开始重新写题解了 A. Palindrome Dance 题意 给出一串由0,1,2表示的数字,0和1分别表示不同的颜色,2表示无色,和两种变色的花费,现在使这串数字变为回文串,使得总花费最小 题解 从左到右,分几种情况讨论下就好了,分类讨论 code #include&amp;amp;amp;lt;iostream&amp;amp;amp;gt; #inc...

Welcome to yjjr's blog! 221

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

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

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

CF 2018.09.06 00:35 题解(补)

比赛题目链接:http://codeforces.com/contest/1040 A. Palindrome Dance A group of nn dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing...

小白 492

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A. Palindrome Dance

problem link:http://codeforces.com/contest/1040/problem/A 题意:给你一个n和一个含有n个数字的数组,其中数组只包含0(白色已买0),1(黑色已买),2(未买);再给你两个值a,b分别代表买一套白色套装的费用和买一套黑色套装的费用。问为了使这个数组成为一个回文串,最少需要花费多少来购买服装。 解题报告: (1)由于n,a,b给的都很小。所...

Light2Chasers的博客 340

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Palindrome (再加多少个字符才能成为回文串 dp)

A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal numb...

自渡的博客 437

A-B Palindrome(回文串 暴力模拟)

You are given a string s consisting of the characters ‘0’, ‘1’, and ‘?’. You need to replace all the characters with ‘?’ in the string s by ‘0’ or ‘1’ so that the string becomes a palindrome and has exactly a characters ‘0’ and exactly b characters ‘1’. No

Lily的博客 414

1136 A Delayed Palindrome (20分)

题目 Consider a positive integer NNN written in standard notation with k+1k+1k+1 digits aia_iai​ as ak⋯a1a0a_k⋯a_1 a_0ak​⋯a1​a0​ with 0≤ai<100\le a_i\lt100≤ai​<10 for all iii and ak>0a_k\gt0ak​...

小白的博客 244

动态规划——Poj 1159 Palindrome

1)   题目 Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 46005   Accepted: 15688 Description A palindrome is a symmetrical s

Vector 4681

A - Palindrome HDU - 6230[马拉车+bit]

题意:给出一个字符串,询问有多少个双回文(形如-----i-----j-----)i,j为对称中心。 题解:可以使用马拉车算法预处理出每个字符为对称中心的回文串长度,然后通过树状数组维护下面的关系 i&amp;lt;ji &amp;lt; ji&lt;j j−r(j)&amp;lt;=ij - r(j) &amp;lt;= ij−r(j)&lt;=i i+r(i)&amp;gt;=ji + r...

Zephyr的博客 407

1328. Break a Palindrome**

1328. Break a Palindrome** https://leetcode.com/problems/break-a-palindrome/ 题目描述 Given a palindromic string palindrome, replace exactly one character by any lowercase English letter so that the strin...

珍妮的选择的博客 495

1136 A Delayed Palindrome (20 分)

Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ with 0≤a​i​​&lt;10 for all i and a​k​​&gt;0. Then N is palindromic if and only if a​i​​=a​k−i​​ for...

acm_zh的博客 609

POJ 1159-Palindrome(dp_回文串+滚动数组)

Palindrome Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description A palindrome is a symmetrical string, that is, a string read identic

Rocky0429 2224

binshenOJ 1215-I Wanna Be A Palindrome (YY)

1215: I Wanna Be A Palindrome 时间限制: 2 Sec  内存限制: 128 MB 提交: 148  解决: 22 [提交][状态][讨论版] 题目描述 给出一个字符串,仅由小写字母组成。请找出是否仅删除其中的一个字母之后, 字符串变成回文串。 输入 输入第一行是一个整数 T,表示有 T 组数据。 每组数据占

kalilili的专栏 980

LeetCode-9 Palindrome Number(判断是否为回文int型)

LeetCode-9 Palindrome Number Determine whether an integer is a palindrome. Do this without extra space.   方法一:直接转String倒置 public class Solution { public boolean isPalindrome(int x) {

你若嘻哈过盛,别人就不再欣赏你的认真 1223
上一篇: CF1042F Leaf Sets
下一篇: CF1040B Shashlik Cooking
ShadyPi
博客等级 码龄9年 1万+粉丝 637原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值