首页 > 其他分享 >Codeforces Round 916 (Div

Codeforces Round 916 (Div

时间:2024-01-26 19:14:39浏览次数:18  
标签:std Lazy 0ll int Codeforces cin ++ Div 916

A Problemsolving Log

题目描述

给一个整数n,字符串s,字符串中s[i]表示第i分钟解决第s[i]题.
问题A需要1分钟解决,问题B需要2分钟解决,以此类推.

问:可以解决多少题?

解题思路

遍历字符串,统计问题A -- Z用了多少时间解决.
最后在遍历数组,判断问题A -- Z是否满足解决时间.

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'

void solve() {
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    std::vector<int> a(26, 0);
    for (auto i: s)
        a[i - 'A']++;
    int cnt = 0;
    for (int i = 0; i < 26; i++)
        if (a[i] >= i + 1)
            cnt++;
    std::cout << cnt << endl;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    int Lazy_boy_ = 1;
    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve();
    return 0;
}

B Preparing for the Contest

题目描述

给两个整数n, k (0 <= k <= n - 1)
问:打印出a[i + 1] > a[i](0<= i < n - 1)的次数等于k的方案.

解题思路

打个比方:
n == 6, k == 2, 我们有这样一个数组[1, 2, 3, 4, 5, 6]
现在将数组重新排序,排序后要满足a[i + 1] > a[i](0<= i < n - 1)的次数等于k.
我们可以将数组后面k + 1个数放在前面,即[4, 5, 6, 1, 2, 3]
多举几个例子就可以发现上述规律.

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'

void solve() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n, 0ll);
    std::iota(a.begin(), a.end(), 1ll);
    for (int i = n - k - 1; i < n; i++)
        std::cout << a[i] << " ";
    for (int i = n - k - 2; i >= 0; i--)
        std::cout << a[i] << " ";
    std::cout << endl;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    int Lazy_boy_ = 1;
    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve();
    return 0;
}

C Quests

题目描述

n个任务,每个任务完成后对应两个值a[i]b[i],首次完成第i个任务时,可获得a[i]分,若此后再完成该任务可获得b[i]
问:现在,可以完成k个任务,可获得的最大分数是多少?

解题思路

枚举走到哪一个位置,然后记录前面的b[i]最大值

代码


#include <bits/stdc++.h>

#define int long long
#define endl '\n'
[[maybe_unused]]typedef std::pair<int, int> pii;

void solve() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n + 1, 0ll), b(n + 1, 0ll);
    for (int i = 0; i < n; i++)
        std::cin >> a[i];
    for (int i = 0; i < n; i++)
        std::cin >> b[i];
    int s = 0, ma = 0, ans = 0;
    for (int i = 0; i < std::min(n, k); i++) {
        s += a[i];
        ma = std::max(ma, b[i]);
        ans = std::max(ans, s + (k - i - 1) * ma);
    }
    std::cout << ans << endl;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    int Lazy_boy_ = 1;
    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve();
    return 0;
}

D Three Activities

题目描述

给出一个n,并且给出这n天参加三项活动的人数a[i], b[i], c[i].

问:最多能有多少人参加这三项活动,并且参加这三项不在同一天.

解题思路

我们只需要模拟一下,但是这个模拟需要优化一下.

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
[[maybe_unused]]typedef std::pair<int, int> pii;

void solve() {
    int n;
    std::cin >> n;
    std::vector<int> a(n, 0ll), b(n, 0ll), c(n, 0ll);
    for (int i = 0; i < n; i++)std::cin >> a[i];
    for (int i = 0; i < n; i++)std::cin >> b[i];
    for (int i = 0; i < n; i++)std::cin >> c[i];
    std::vector<int> x(n, 0ll);
    std::iota(x.begin(), x.end(), 0ll);
    auto y = x, z = x;
    std::sort(x.begin(), x.end(), [&](int aa, int bb) { return a[aa] > a[bb]; });
    std::sort(y.begin(), y.end(), [&](int aa, int bb) { return b[aa] > b[bb]; });
    std::sort(z.begin(), z.end(), [&](int aa, int bb) { return c[aa] > c[bb]; });
    int w = std::min({n, 100ll}), ans = 0ll;
    for (int i = 0; i < w; i++)
        for (int j = 0; j < w; j++)
            for (int k = 0; k < w; k++)
                if (x[i] != y[j] && x[i] != z[k] && y[j] != z[k])
                    ans = std::max(a[x[i]] + b[y[j]] + c[z[k]], ans);
    std::cout << ans << endl;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    int Lazy_boy_ = 1;
    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve();
    return 0;
}

标签:std,Lazy,0ll,int,Codeforces,cin,++,Div,916
From: https://www.cnblogs.com/Lazyboyjdj/p/17990493

相关文章

  • Educational Codeforces Round 159 (Rated for Div
    EducationalCodeforcesRound159(RatedforDiv.2)ABinaryImbalance题目大意给定一个长度为n的一个01字符串,我们执行以下操作:当s[i]!=s[i+1]在中间插入0问:是否可以实现0的个数大于1的个数解题思路由题意可以明显看出只要有0就可以实现。下面简单分析下:0的个数大......
  • Educational Codeforces Round 160 (Rated for Div
    ARatingIncreas题目大意给定一个数字,让我们拆分成两个数,这两个数满足以下条件:a<b.两个数没有前缀0.问:输出满足条件的数a,b.解题思路直接暴力循环这个数的位数次,若满足a<b,再判断两个数的位数和是否与拆分前相同.代码#include<bits/stdc++.h>#defin......
  • Educational Codeforces Round 161 (Rated for Div
    ATrickyTemplate题目描述给一个数字n和三个长度为n的字符串a,b,c。找一个模板使得字符串a,b匹配,而c不匹配,是否存在这样一个模板.匹配的定义是:当模板字母为小写时,两个字符串字符相同,为大写时,两个字符不同,这样的两个字符串则匹配解题思路我们可以直接得出当a字符串......
  • hey_left 17 Codeforces Round 817 (Div. 4)
    题目链接A.把标准字符串和输入字符串排序,看是否相等#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10;voidsolve(){intn;cin>>n;stringt;cin>>t;strings="Timur";sort(s.begin(),s.end());......
  • hey_left 16 Codeforces Round 827 (Div. 4)
    题目链接A.判最大的数是不是另外两个数的和#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10;voidsolve(){inta,b,c;cin>>a>>b>>c;cout<<(max({a,b,c})==a+b+c-max({a,b,c})?"YES":"......
  • Codeforces 1667E Centroid Probabilities
    这个连边方式就可以理解为\(1\)为根,点\(u\)的父亲\(fa_u\)满足\(fa_u<u\)。重心有不止一种表示法,考虑用“子树\(siz\ge\lceil\frac{n}{2}\rceil\)最深的点”来表示重心。令\(m=\lceil\frac{n}{2}\rceil\),\(f_i\)为节点\(i\)的\(siz\gem\)的方案数。考虑枚......
  • Codeforces Round 920 (Div. 3)
    赛时过了A~E,表现分1738。感觉D~G都挺有意义拿出来说的。[D]VeryDifferentArray首先一个贪心的猜想是:如果A和B长度相同,那一个顺序一个逆序应该是最优的情况。思考下如何证明这个猜想。假如A和B的长度均为2,易证\(A_1\)<\(A_2\),\(B_1\)>\(B_2\)时最优......
  • CodeForces 1667E Centroid Probabilities
    洛谷传送门CF传送门首先需要了解重心的三种定义:删掉一个点后剩下子树大小\(\le\frac{n}{2}\)的点\(\sum\limits_{i=1}^n\text{dis}(u,i)\)最小的点最深的\(sz_u\ge\left\lceil\frac{n}{2}\right\rceil\)的点这道题我们使用第三种定义,也就是要统计\(i\)为最......
  • Codeforces round 919 (div2)
    Problem-A-Codeforces暴力枚举就可以;#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;vector<int>a;intn;signedmain(){int_;cin>>_;while(_--){a.clear();cin>>n;......
  • hey_left 15 Codeforces Round 835 (Div. 4)
    题目链接A.总和-最小值-最大值即为中间数#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){inta,b,c;cin>>a>>b>>c;cout<<a+b+c-min({a,b,c})-max({a,b,c})<<'\n';}signedmain(){io......