zoukankan      html  css  js  c++  java
  • Codeforces Round #624 (Div. 3) (A~D,CD Good)

    比赛链接:Here

    1311A. Add Odd or Subtract Even

    签到题,

    • (a > b) 时必须做做减法,如果差值为偶数的话只需要 (1) 次不然做一次减法后再做一次 (+1) 即可
    • (a < b) 同理了
    • (a = b) 0次
    int main() {
        cin.tie(nullptr)->sync_with_stdio(false);
        int _; for (cin >> _; _--;) {
            ll a, b;
            cin >> a >> b;
            if (a == b) cout << "0
    ";
            else if (a > b) {
                if ((a - b) & 1) cout << "2
    ";
                else cout << "1
    ";
            } else {
                if ((a - b) & 1) cout << "1
    ";
                else cout << "2
    ";
            }
        }
    }
    

    1311B. WeirdSort

    题意:给出长度为 (n)​ 的数组以及长度为 (m)​ 的允许进行 (swap(a[i],a[i + 1])) 的下标,

    问经过若干次之后是否能使得数组有序

    思路:

    注意到 (nle 100) 那么我可以直接跑若干次循环对于 (a[i] < a[i + 1]) 的地方交换 (前提是允许交换),

    如果最后有序了就输出 YES

    const int N = 110;
    int a[N], st[N];
    int main() {
        cin.tie(nullptr)->sync_with_stdio(false);
        int _; for (cin >> _; _--;) {
            int n, m;
            cin >> n >> m;
            for (int i = 1; i <= n; ++i) cin >> a[i];
            memset(st, 0, sizeof(st));
            for (int i = 1, x; i <= m; ++i) cin >> x, st[x] = 1;
            for (int i = 0; i < n; ++i)
                for (int j = 1; j < n; ++j)
                    if (a[j] > a[j + 1] and st[j]) swap(a[j], a[j + 1]);
            bool f = 1;
            for (int i = 1; i < n and f; ++i) if (a[i] > a[i + 1]) f =  0;
            cout << (f ? "YES
    " : "NO
    ");
        }
    }
    

    1311C. Perform the Combo

    题意:给一个长度为n的字符串 会犯m个错误 每次犯错误就要重新输入

    问你所有字母共打了多少次?

    思路

    似乎很多人用前缀和写的,

    我的思路是在某个位置去二分找是否有若干次在它之后会出错的次数并累计即可。

    int cnt[300];
    int main() {
        cin.tie(nullptr)->sync_with_stdio(false);
        int _; for (cin >> _; _--;) {
            memset(cnt, 0, sizeof(cnt));
            int n, m;
            string s;
            cin >> n >> m >> s;
            vector<int>p;
            for (int i = 0, x; i < m; ++i) {
                cin >> x;
                p.emplace_back(x);
            }
            sort(p.begin(), p.end());
            for (int i = 0; i < n; ++i) {
                int t = p.end() - lower_bound(p.begin(), p.end(), i + 1);
                cnt[s[i]] += 1 + t;
                // cout << s[i] << ": " << t << "
    ";
            }
            for (auto c = 'a'; c <= 'z'; ++c) cout << cnt[c] << " ";
            cout << "
    ";
        }
    }
    

    1311D. Three Integers

    题意:

    给了(a、b、c) 三个数,现在你可以对任意一个数进行任意次数的 (+1)(-1) 问你最少操作次数让(b\%a=0,c\%b=0)

    思路:

    (a,b,c) 改变的最大范围也就是 ([1,10000]),直接枚举就可以,但是 (10000^3)​ 明显是会超时的。这里稍微优化一下。

    int main() {
        cin.tie(nullptr)->sync_with_stdio(false);
        int _; for (cin >> _; _--;) {
            int a, b, c;
            cin >> a >> b >> c;
            int aa = a, bb = b, cc = c;
            int cnt = INT_MAX;
            for (int i = 1; i <= 11000; ++i)
                for (int j = 1; i * j <= 11000; ++j)
                    for (int k = 1; i * j * k <= 11000; ++k) {
                        if (cnt > abs(i - a) + abs(i * j - b) + abs(i * j * k - c)) {
                            cnt = abs(i - a) + abs(i * j - b) + abs(i * j * k - c);
                            aa = i, bb = i * j, cc = i * j * k;
                        }
                    }
            cout << cnt << "
    " << aa << " " << bb << " " << cc << "
    ";
        }
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    【Delphi】VCL 使用TCoolBar控件,在系统触发UAC界面时,引发CMSysFontChanged事件导致界面卡死或弹出System Error 1400错误
    【Delphi】 FMX 下 TImageList的使用方法:获取其中一张图片
    如何在电脑睡眠状态下保持程序运行
    【Delphi】使用TIdHTTPServer开发HTTP服务端在Windows2008部署后,外网无法访问
    fedora 25 virtualbox 增强功能安装
    在Win8系统中如何将一般类型的文件放在开始菜单中
    mac上的替代软件
    spring boot 1.4.1 with jsp file sample
    macbook pro 重装系统
    找不到或无法加载主类 org.codehaus.plexus.classworlds.launcher.Launcher
  • 原文地址:https://www.cnblogs.com/RioTian/p/15190470.html
Copyright © 2011-2022 走看看