zoukankan      html  css  js  c++  java
  • 【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
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    iOS 界面翻转切换动画
    深度解析Objective-C笔试题
    Objective-C内存管理基础
    Objective-C入门教材
    Objective-C代码学习大纲(6)
    Objective-C代码学习大纲(5)
    Objective-C代码学习大纲(4)
    sharedPreferences
    ListView判断滑动底部
    Oracle 游标疑问
  • 原文地址:https://www.cnblogs.com/AWCXV/p/9597251.html
Copyright © 2011-2022 走看看