首页 > 其他分享 >Educational Codeforces Round 9

Educational Codeforces Round 9

时间:2023-01-02 23:34:46浏览次数:57  
标签:Educational sufA int Codeforces long cin ++ ans Round

Educational Codeforces Round 9

https://codeforces.com/contest/632
3/6: ABC

A. Grandma Laura and Apples

模拟

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 45;
int n, m, a[N], ans, money;

signed main () {
    cin >> n >> m;
    string s;
    m /= 2;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s.size () == 8)     a[i] = 1;
    }
    for (int i = n - 1; i >= 0; i--) {
        money *= 2;
        if (a[i])   money ++;
        ans += money;
    }
    cout << m * ans;

}

//x = 2^{n-1} + 2^{cnt-1} - 1
//

B. Alice, Bob, Two Teams

前缀和

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 5e5 + 5;
int n, a[N], ans;
int preA[N], preB[N], sufA[N], sufB[N];

signed main () {
    string s;
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    cin >> s;
    s = ' ' + s;
    for (int i = 1; i <= n; i++) {
        preA[i] = preA[i-1], preB[i] = preB[i-1];
        if (s[i] == 'A')    preA[i] += a[i];
        else    preB[i] += a[i], ans += a[i];
    }
    for (int i = n; i >= 1; i--) {
        sufA[i] = sufA[i+1], sufB[i] = sufB[i+1];
        if (s[i] == 'A')    sufA[i] += a[i];
        else    sufB[i] += a[i];
    }
    for (int i = 1; i <= n; i++) {
        //假设在i翻转前缀
        ans = max (ans, preA[i] + sufB[i+1]);
    }
    for (int i = n; i >= 1; i--) {
        //假设在i翻转后缀
        ans = max (ans, sufA[i] + preB[i-1]);
    }
    cout << ans;
}

C. The Smallest String Concatenation

排序水题

#include <bits/stdc++.h>

using namespace std;
const int N = 5e4 + 5;
int n;
string s[N];

bool cmp (string a, string b) {
    return a + b < b + a;
}

int main () {
    cin >> n;
    for (int i = 0; i < n; i++)     cin >> s[i];
    sort (s, s + n, cmp);
    for (int i = 0; i < n; i++)     cout << s[i];
}

D. Longest Subsequence

离散化 + 筛因数
这题其实非常简单,但是当时没思考qaq

// LUOGU_RID: 98487907
#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1e6 + 5;
int n, m, a[N], cnt[N], b[N], ans[N];
int lcm = 1, tot, k;

signed main () {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] > m)   continue;
        b[k++] = a[i], cnt[a[i]] ++;
    }
    sort (b, b + k);
    k = unique (b, b + k) - b;
    for (int i = 0; i < k; i++) {
        for (int j = b[i]; j <= m; j += b[i])     ans[j] += cnt[b[i]];
    }
    for (int i = 1; i <= m; i++) {
        if (ans[i] > tot)   tot = ans[i], lcm = i;
    }
    
    cout << lcm << ' ' << tot << endl;
    for (int i = 1; i <= n; i++) {
        if (lcm % a[i] == 0)    cout << i << ' ';
    }    
}

剩下眼睛不舒服,明天补

E. Thief in a Shop

F. Magic Matrix

标签:Educational,sufA,int,Codeforces,long,cin,++,ans,Round
From: https://www.cnblogs.com/CTing/p/17020833.html

相关文章

  • Codeforces Good Bye 2022 CF 1770 F Koxia and Sequence 题解
    题目链接注意题目要求的是所有好序列的所有元素的XOR之和的XOR之和。我一开始以为是所有XOR之和的加法和导致不知道官方题解在讲什么。假设我们枚举一个位置\(1\lei\le......
  • Codeforces Round #781 (Div. 2)C
    CodeforcesRound#781(Div.2)CC我之前没有看懂题目,我现在把我认为正确的题意描述出来有一棵树,一开始都没有病毒什么的,但是我们需要把这一棵树里的所有节点变成有病......
  • Codeforces 1389 B. Array Walk 做题记录(DP)
    (纯种的DP还是做得有点苦痛,调了好久。太菜了。)大概就是第一层枚举返回几次,第二层遍历一遍$1~n$。#include<bits/stdc++.h>usingnamespacestd;constintm......
  • Codeforces Round #812 (Div. 2)
    题目链接A核心思路:其实我们需要挖掘出一个性质,那就是任何一个答案都必然是个长方形。所以我们只需要计算长方形的一个周长就好了。为什么有这样一个性质呢,因为我们发现任......
  • 半透明边框与background-clip
    一,半透明边框前言:已知,通过rgba与hsla颜色我们可以设置半透明的颜色,现在我们想实现一个半透明的边框,例子如下:border:10pxsolidhsla(0,0%,100%,.5);background:wh......
  • Codeforces Round 789 div2 A-E题解 & 处理手法思考
    A.TokitsukazeandAllZeroSequence这题给一个数列,每次操作对于两个不相同的数字可以吧大的变成min,两个相同的话一个变为0问最少操作多少次能将整个数组变为0首......
  • Codeforces 22 B. Bargaining Table 做题记录
    其实是比较基础的模拟($n<=25$),写个$O(n^4)$的暴力就过了。感觉可以用倍增优化一下,可以但没必要。……太菜了还挂了几发。反思一下,一个是写函数改来改去int类型没返......
  • C. Koxia and Number Theory (线性同余)https://codeforces.com/contest/1770/problem/C
    https://codeforces.com/contest/1770/attachments/download/18470/editorial.pdf这个pdf都写得很明白了,这个c题终于懂了,麻了à$a_i^j\leqb^j$本来只需要枚举n/2之内的......
  • C. On Number of Decompositions into Multipliers -- Codeforces
    C.OnNumberofDecompositionsintoMultipliershttps://codeforces.com/problemset/problem/397/C 思路  Codehttps://codeforces.com/contest/397/submissi......
  • Codeforces Round #840 (Div. 2) and Enigma 2022 - Cybros LNMIIT A--B
    ​​https://codeforces.com/contest/1763​​A.AbsoluteMaximization二进制操作经典的利用二进制位数操作的题,|和&。最大值肯定是所有元素的或。最小值是所有元素的与......