【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
i从1..n/2循环一波。
保证a[i]和a[n-i+1]就好。
如果都是2的话填上min(a,b)*2就好
其他情况跟随非2的。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 20;
int n,a,b,cost[2];
int c[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
scanf("%d%d%d",&n,&a,&b);
cost[0] = a,cost[1] = b;
rep1(i,1,n) scanf("%d",&c[i]);
int ans = 0;
rep1(i,1,n/2){
int l = i,r = n-i+1;
if (c[l]==2 && c[r]==2){
ans+=min(a,b)*2;
}else{
if (c[l]==2){
ans+=cost[c[r]];
}else if (c[r]==2){
ans+=cost[c[l]];
}else if (c[l]!=c[r]){
cout<<-1<<endl;
return 0;
}
}
}
if (n&1){
if (c[n/2+1]==2){
ans+=min(a,b);
}
}
printf("%d\n",ans);
return 0;
}
【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance的更多相关文章
- 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 翻转一次最多影响2k+1个地方. 如果n<=k+1 那么放在1的位置就ok.因为能覆盖1..k+1 如果n<=2k+1 ...
- Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) D mt19937
https://codeforces.com/contest/1040/problem/D 用法 mt19937 g(种子); //种子:time(0) mt19937_64 g(); //long ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)
D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartme ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned tha ...
- 【Codeforces Round #430 (Div. 2) A C D三个题】
·不论难度,A,C,D自己都有收获! [A. Kirill And The Game] ·全是英文题,述大意: 给出两组区间端点:l,r,x,y和一个k.(都是正整数,保证区间不为空),询问是否 ...
随机推荐
- ASP内置对象—Request、Response 、Server、Application 、ObjectContent (二)
Response (应答)对象 Request 对象.用于在HTTP请求期间,訪问不论什么client浏览器传递给server的信息,包含通过URL传递的參数信息.使用GET方法或POST方法传递的H ...
- Oracle-11-主键约束
一.Oracle系统一共提供了下面5种约束 1.非空(NOT NULL)约束:所定义的列绝不能为空: 2.唯一(UNIQUE)约束:在表中每一行中所定义的列,其列值不能同样: 3.主键(PARIMAR ...
- 【剑指Offer学习】【面试题34:丑数】
题目:我们把仅仅包括因子2.3 和5 的数称作丑数(Ugly Number).求从小到大的顺序的第1500个丑数. 举例说明: 比如6.8 都是丑数.但14 不是.它包括因子7.习惯上我们把1 当做第 ...
- 【翻译自mos文章】 asmcmd cp命令不能拷贝大于2GB的文件。
asmcmd cp命令不能拷贝大于2GB的文件. 參考原文: Asmcmd CP Command Can Not Copy Files Larger Than 2 GB (Doc ID 786258. ...
- 【待解决】创建maven web工程报错
报错信息如下: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 o ...
- '无法将“vue”项识别为 cmdlet、函数、脚本文件或可运行程序的名称' 或 'vue不是内部或外部命令' 的解决方法
如果在使用 vue 初始化项目的时候提示: vue : 无法将“vue”项识别为 cmdlet.函数.脚本文件或可运行程序的名称.请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次. 或者: ...
- Linux - xshell 链接CentOS 设置高亮
默认是黑白的! 用了vim 指令还是黑白的. 两种途径设置,一种是通过Alt+P. 一种是选择配色方案来设置.
- php 写日志函数(原创)
function write_log($msg,$isEcho=false,$path=''){ $path?'':$path='logs'.DIRECTORY_SEPARATOR.'log'.dat ...
- Arduino-IIC-Wire.h
前言:Wire.h是Arduino的IIC库. 一.Wire库函数 Wire.begin() Wire.requestFrom() Wire.beginTransmission() Wire.endT ...
- tinyxml使用
1.下载地址 http://sourceforge.net/projects/tinyxml/ 2.tinyxml不仅支持Linux编译,同时也支持windows下编译,由于tinyxml仅有6个文件 ...