Codeforces Round #582 (Div. 3)

A
输出奇数位和偶数位的最大值即可

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
 
int main()
{
    int cntodd = 0, cnteven = 0, n; cin >> n;
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        if (x & 1) cntodd++; else cnteven++;
    }
    cout << min(cntodd, cnteven) << endl;
}

B
从后往前维护最小值

#include <bits/stdc++.h>
using namespace std;
const int maxn = 150000 + 5;
int a[maxn];
 
int main()
{
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        for (int i = 0; i < n; ++i) cin >> a[i];
        int minn = a[n - 1], ans = 0;
        for (int i = n - 2; i >= 0; --i) {
            if (a[i] > minn) ans++;
            else minn = a[i];
        }
        cout << ans << endl;
    }
}

C
预处理m%10=1-9的循环节

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> pre[15];
int sum[15];
int main()
{
    pre[0].push_back(0); sum[0] = 0;
    for (int i = 1; i <= 9; ++i) {
        pre[i].push_back(i);
        for (int j = 2; ; ++j) {
            int now = i * j;
            if (pre[i][0] == now % 10) break;
            pre[i].push_back(now % 10);
        }
        for (int j = 0; j < pre[i].size(); ++j) sum[i] += pre[i][j];
    }
    int q; cin >> q;
    while (q--) {
        ll n, m; cin >> n >> m;
        ll cnt = n / m; int k = m % 10;
        //cout << cnt << ", " << k << endl;
        ll ans = sum[k] * (cnt / pre[k].size());
        for (int i = 0; i < (cnt % pre[k].size()); ++i) ans += pre[k][i];
        cout << ans << endl;
    }
}
 

D
处理出每个数/2->0的结果,用vector存在到达这个数的组成情况,答案即是数量>=k的前k小的和

#include <bits/stdc++.h>
using namespace std;
const int maxn = 50 + 5;
const int maxm = 2e5 + 5;
int n, k;
int a[maxn];
vector<int> res[maxm];
int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) {
        int tmp = a[i], j = 0;
        while (true) {
            res[tmp].push_back(j);
            if (!tmp) break;
            tmp /= 2; j++;
        }
    }
    int ans = maxm;
    for (int i = 0; i < maxm; ++i) {
        if (res[i].size() < k) continue;
        sort(res[i].begin(), res[i].end());
        int tmp = 0;
        for (int j = 0; j < k; ++j) tmp += res[i][j];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

E
只可能是abc的全排列重复n此或a…b…c…

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
 
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n; string s, t; cin >> n >> s >> t;
    string num = "abc";
    vector<string> v;
    do {
        string ans;
        for (int i = 0; i < n; ++i) ans += num;
        v.push_back(ans);
        v.push_back(string(n, ans[0]) + string(n, ans[1]) + string(n, ans[2]));
    } while (next_permutation(num.begin(), num.end()));
    for (auto i : v) {
        if (i.find(s) == string::npos && i.find(t) == string::npos) {
            cout << "YES" << endl;
            cout << i << endl;
            return 0;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值