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
  • 相关阅读:
    一本通 P1806 计算器
    英语单词
    Dubbo springboot注解
    java连接zookeeper集群
    zookeeper集群
    入住博客园!
    解决 windows MySQL安装过程中提示计算机丢失vcruntime140_1.dll
    django 订单并发修改库存乐观悲观锁
    毒鸡汤
    Java反射机制
  • 原文地址:https://www.cnblogs.com/xcfxcf/p/12483399.html
Copyright © 2011-2022 走看看