首页 > 其他分享 >Codeforces Round 913 (Div. 3)

Codeforces Round 913 (Div. 3)

时间:2023-12-17 16:45:24浏览次数:24  
标签:int dig Codeforces st -- solve Div 借数 913

Codeforces Round 913 (Div. 3)

A:ABC

A. Rook

简单题,就两个循环搞定(直接上码)

#include <bits/stdc++.h>

using namespace std;

void solve() {
    char a;
    int b;
    cin >> a >> b;
    for (int i = 1; i <= 8; i++) {
        if (i != b) {
            cout << a << i << endl;
        }
    }
    for (int i = 0; i < 8; i++) {
        char x = 'a' + i;
        if (x != a) {
            cout << x << b << endl;
        }
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

B. YetnotherrokenKeoard

题意:遇到'B'右边第一个大写字母删除,遇到'b'右边第一个小写字母删除

思路:从后往前遍历,然后记录bB的数量

最开始想太多直接从前面遍历然后就T了,后面一想发现自己好傻

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e6 + 10;
char a[MAX];

void solve() {
    string st;
    cin >> st;
    int x1 = 0, x2 = 0;
    int l = 0;
    for (int i = st.size() - 1; i >= 0; i--) {
        if (st[i] == 'b') {
            x1++;
        } else if (st[i] == 'B') {
            x2++;
        } else if (st[i] >= 'a' && st[i] <= 'z' && x1) {
            x1--;
        } else if (st[i] >= 'A' && st[i] <= 'Z' && x2) {
            x2--;
        } else {
            a[l] = st[i];
            l++;
        }
    }
    for (int i = l - 1; i >= 0; i--) {
        cout << a[i];
    }
    cout << "\n";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

C. Removal of Unattractive Pairs

题意:删除两个相同的字符,使得字符串长度最短

思路:统计最多的字符的数量

#include <bits/stdc++.h>

using namespace std;
#define int long long
int a[26];

void solve() {
    memset(a, 0, sizeof a);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        char x;
        cin >> x;
        a[x - 'a']++;
    }
    int ma = 0;
    for (int i = 0; i < 26; i++) {
        ma = max(a[i], ma);
    }
    //cout<<"ma:"<<ma<<"\n";
    if (ma * 2 >= n) {
        cout << ma * 2 - n << "\n";
    } else {
        if (n % 2) {
            cout << "1\n";
        } else cout << "0\n";
        /*
        int res = 0;
        sort(a, a + 26);
        for (int i = 25; i >= 0; i--) {
            cout << "res:" << res << "\n";
        }
        cout << abs(res) << endl;
         */
    }
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

D. Jumping Through Segments

题意:给定n个区间,每次跳到一个区间求跳跃距离的最小值

思路:最大值的最小,所以:二分!!!

(都是给n个区间,直接想成acvv上的板子题了,于是sort一下就出来了,然后样例给了我狠狠一击)

#include <bits/stdc++.h>

using namespace std;
const int MAX = 2e5 + 10;
int l[MAX], r[MAX];
int n;

bool check(int k) {
    int lx = 0, rx = 0;
    for (int i = 1; i <= n; i++) {
        int l1 = lx - k, r1 = rx + k;
        if (l1 > r[i] || r1 < l[i]) {
            return false;
        }
        lx = max(l1, l[i]);
        rx = min(r[i], r1);
    }
    return true;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
    }
    int L = 0, R = 1e10;
    while (L <= R) {
        int m = (L + R) >> 1;
        if (check(m)) R = m - 1;
        else L = m + 1;
    }
    cout << R + 1 << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

E. Good Triples

题意:有一个三元组让
$$
digsum(a)+digsum(b)+digsum(c)=digsum(n)
$$

$$
a+b+c=n
$$

思路:可以从每一个数位上下手至于证明这东西我证不出来于是直接贴一个知乎上大佬的证明算了

证明:

假设求和时向高一位借数了,比如借了一个数。

如果高一位>=1,不会向高二位借数,相对于不借数的情况,左边的dig+10,右边的dig+1,这样在这一位左边的显然增加了9,高一位考虑答案时和当前位一样,左右的dig差值只会更大。举个例子,9+1+2=12

如果高二位==0,向高二位借数,这里假设能借到数,相对于不借数的情况,左边当前位dig+10,高一位dig+9,右边dig+1,右边高位如果借不到数还要增加dig,左右dig差值至少增加了18。举个例子,2+99+1=102

借两个数也是一样,也就是说只要借数了必然会导致dig的增加

考虑单独一位,只有不借数左右两边的dig才能相等!

#include <bits/stdc++.h>

using namespace std;
#define int long long
int cnt[20];

void solve() {
    string n;
    cin >> n;
    int res = 1;
    for (int i = 0; i < n.size(); i++) {
        res *= cnt[n[i] - '0'];
    }
    cout << res << endl;
}

void init() {
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j + i <= 9; j++) {
            for (int k = 0; i + j + k <= 9; k++) {
                cnt[i + k + j]++;
            }
        }
    }
}

signed main() {
    int t;
    cin >> t;
    init();
    while (t--) {
        solve();
    }
}

标签:int,dig,Codeforces,st,--,solve,Div,借数,913
From: https://www.cnblogs.com/bbbbear/p/17909284.html

相关文章

  • Codeforces Round 863 (Div. 3)
    CodeforcesRound863(Div.3)A.InsertDigit题意:插入一个字母使得这个数字最大化思路:只要从前往后便利就行#include<iostream>usingnamespacestd;voidsolve(){intn,k;cin>>n>>k;boolx=true,y=false;for(inti=0;i<n;i++){......
  • Codeforces Round 913 (Div. 3)
    CF1907总结A.Rook题面翻译给出车在国际象棋棋盘中的位置,输出其可到达的坐标(不必在意顺序)。车可以横着或竖着走任意格数。分析题意明了,输出车所在行和列所有格子的序号(除车所在位置外)。code#include<bits/stdc++.h>usingnamespacestd;intt;voidsolve(){ string......
  • Codeforces Round 891 (Div3)
    CodeforcesRound891(Div.3)A.ArrayColoring这个我vp的时候写复杂了,想不到答案的思路这么清晰,将两部分分别看,将偶数加进去其奇偶性不变,只有奇数加进去才会改变奇偶性,so只有改变偶数次奇偶性才能使其奇偶性相同,所以cnt%2==0.#include<bits/stdc++.h>usingnamespacestd;......
  • Codeforces Round 816 (Div. 2) VP
    基本情況A秒了,B错一次之后也过了,C没思路。B.BeautifulArrayProblem-B-Codeforcesvoidsolve(){ longlongn,k,b,s; memset(ans,0,sizeof(ans)); std::cin>>n>>k>>b>>s; if(s<b*k){std::cout<<"-1\n";ret......
  • Codeforces Round 815 (Div. 2)
    基本情况脑子太不清楚了。A题有思路,但是各种细节问题(数论题太不熟练了),错了好几次才过。B题直接分析数据愣猜一个解,猜对了。A.BurenkaPlayswithFractionsProblem-A-Codeforces难点在分析输出\(1\)的情况。我的想法是通分,然后直接比分子是否互相整除,想法很对,但是......
  • Codeforces Round 915 (Div. 2)
    A.ConstructiveProblems看了一眼数据,猜测可能是n,m里的最大#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ inta,b; cin>>a>>b; intans=max(a,b); cout<<ans<<"\n";}intmain(){ ios::sync_with_stdio(false);cin.tie......
  • Codeforces Round 915 (Div. 2)
    CodeforcesRound915(Div.2)唉,菜狗。A-CoverinWaterintmain(){IOS;for(cin>>_;_;--_){cin>>n>>m;cout<<max(n,m)<<'\n';}return0;}B-Begginer'sZelda除......
  • Educational Codeforces Round 159 (Rated for Div. 2) C. Insert and Equalize (贪心+
    EducationalCodeforcesRound159(RatedforDiv.2)C.InsertandEqualize思路:首先对\(a\)进行排序,然后对所有差值取gcd,获得可用的最大因子\(gc\),答案有两种情况:一种是\(a_{n+1}\)在$a_1\(~\)a_n$范围内,这时要获得最大的位置一种情况是$a_1\(~\)a_n$......
  • [Codeforces] CF1774B Coloring
    CF1774BColoring题意Cirno_9baka的纸条上有\(n\)个格子,他觉得空白的纸条看着有点无趣,于是想在纸条的格子上涂上\(m\)种颜色。同时,他认为第\(i\)种颜色必须要用\(a_i\)次,且每连续\(k\)个格子里涂的颜色必须互不相同。Cirno_9baka想知道有没有这样的一种涂色方案能......
  • [Codeforces] CF1760F Quests
    CF1760FQuests题意有\(n\)个任务,你每一天都可以选择其中的一个任务完成或不选。当你完成了第\(i\)个任务,你将获得\(a_i\)元。但是如果你今天完成了一个任务,那么你之后\(k\)天内都不能再完成这个任务。给出两个数\(c\),\(d\),要求求出满足在\(d\)天内可以收集至少\(c......