zoukankan      html  css  js  c++  java
  • “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛(2018)

    https://ac.nowcoder.com/acm/contest/123

    A  Anagram

    不得不说,还是不喜欢英文的题面

    题意:由a到b变化次数最少是多少

    先排序,如果一样,说明是0

    不一样,根据规则

    a <= b,  b - a;

    否则 a先变道Z 再到b; 此时 我们可以想想一个圆,变化次数就是26 - (a - b)要想次数最少,也就是a - b最大,所以a的最后一个 和此时的b

    #include<bits/stdc++.h>
    
    using namespace std;
    string a, b;
    
    int main() {
        //freopen("in","r",stdin);
        ios::sync_with_stdio(0);
        while (cin >> a >> b) {
            int s = 0;
            int s1 = 0, s2 = a.length() - 1;
            sort(a.begin(), a.end());
            sort(b.begin(), b.end());
            for (int i = 0; i < a.length(); i++) {
                if (a[s1] <= b[i])
                    s += b[i] - a[s1++];
                else
                    s += 26 - (a[s2--] - b[i]);
            }
            cout << s << endl;
        }
        return 0;
    }
    View Code

    C cities

    #include<bits/stdc++.h>
    
    using namespace std;
    #define int long long
    const int maxn = 1e5 + 5;
    int t,n;
    int ans;
    int a[maxn];
    signed main() {
        freopen("in","r",stdin);
        ios::sync_with_stdio(0);
        cin >> t;
        while (t--) {
            ans = 0;
            cin >> n;
            for (int i = 0; i < n; i++)
                cin >> a[i];
            sort(a,a+n);
            for (int i = 1; i < n; i++)
                ans += a[i];
            cout << ans + a[0] * (n - 1)<< endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    堆排序
    2019晋城一中开放日
    严格次小生成树
    遥远的国度
    noip2018游记
    Luogu1736 创意吃鱼法
    P3958 奶酪
    Luogu3385 负环
    Luogu1040 加分二叉树
    Luogu1007 独木桥
  • 原文地址:https://www.cnblogs.com/xcfxcf/p/12483399.html
Copyright © 2011-2022 走看看