首页 > 其他分享 >Codeforces Round 964 (Div. 4)

Codeforces Round 964 (Div. 4)

时间:2024-08-10 10:27:45浏览次数:16  
标签:964 r1 r2 int Codeforces else ++ ans Div

这场的题不错,就是一直在 i n q u e u e in queue inqueue,体验感很是不好,导致我 B C B C BC两题一个小时才过, 还好写了 7 7 7题,差一点点就 A K AK AK了

A. A+B Again?

思路: 输出数位之和

void solve() {
    int ans = 0;
    string s; cin >> s;
    for (auto i : s) ans += (i - '0');
    cout << ans << '\n';
}

B. Card Game

思路: 写成答辩了,直接按照题意模拟

void solve() {
    int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4;
    int ans = 0, r1 = 0, r2 = 0;
    if (a1 > a3) r1 ++;
    else if (a1 < a3) r2 ++;
    if (a2 > a4) r1 ++;
    else if (a2 < a4) r2 ++;
    if (r1 > r2) ans ++;

    r1 = 0, r2 = 0;
    if (a1 > a4) r1 ++;
    else if (a1 < a4) r2 ++;
    if (a2 > a3) r1 ++;
    else if (a2 < a3) r2 ++;
    if (r1 > r2) ans ++;

    r1 = 0, r2 = 0;
    if (a2 > a3) r1 ++;
    else if (a2 < a3) r2 ++;
    if (a1 > a4) r1 ++;
    else if (a1 < a4) r2 ++;
    if (r1 > r2) ans ++;

    r1 = 0, r2 = 0;
    if (a2 > a4) r1 ++;
    else if (a2 < a4) r2 ++;
    if (a1 > a3) r1 ++;
    else if (a1 < a3) r2 ++;
    if (r1 > r2) ans ++;
    cout << ans << '\n';
}

C. Showering

思路:看看再 0 0 0 ~ m m m之间有没有连续一段空闲的时间超过 s s s就行,模拟

void solve() {
    int n, s, m; cin >> n >> s >> m;
    int lst = 0;
    bool ok = false;
    for (int i = 1; i <= n; i ++) {
        int l, r; cin >> l >> r;
        if (l - lst >= s) ok = true;
        lst = r;
    }
    if (m - lst >= s) ok = true;
    if (ok) cout << "YES\n";
    else cout << "NO\n";
}

D. Slavic’s Exam

思路: 将字符串 t t t 插入到 s s s 串为 ? ? ? 的地方, t t t 串能被插完就可以,否则不行

void solve() {
    string s, t; cin >> s >> t;
    for (int i = 0, j = 0; i < s.size() && j < t.size(); i ++) {
        if (s[i] == t[j]) j ++;
        else {
            if (s[i] == '?') s[i] = t[j ++];
        }
    }
    for (int i = 0; i < s.size(); i ++) {
        if (s[i] == '?') s[i] = 'a';
    }
    int j = 0;
    for (int i = 0; i < s.size() && j < t.size(); i ++) {
        if (s[i] == t[j]) j ++;
    }
    if (j == (int)t.size()) {
        cout << "YES" << '\n';
        cout << s << '\n';
    } else cout << "NO" << '\n';
}

E. Triple Operations

思路:肯定是先把一个较小的数变为零以后,剩下的数直接一直除 3 3 3即可,但要记得把每个数能被 3 3 3除的次数预处理,不然会 t l e tle tle

// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define debug1(a) cout << #a << '=' << a << endl
#define debug2(a, b) cout << #a << '=' << a << ' ' << #b << '=' << b << endl
#define lf(x) fixed << setprecision(x)
#define int long long
const int N = 200010;
const int INF = 0x3f3f3f3f;

using namespace std;

int get(int x) {
    int cnt = 0;
    while (x) {
        cnt ++;
        x /= 3;
    }
    return cnt;
}

int s[N];

void solve() {
    int l, r; cin >> l >> r;
    int ans = 0, pos;
    if (l == 1) ans += 3, pos = 3;
    else {
        int x = get(l);
        int r = l + 1;
        for (int i = 1; i <= x; i ++) r *= 3;
        int y = get(r);
        ans += x + y;
        pos = l + 2;
    }
    ans += s[r] - s[pos - 1];
    cout << ans << '\n';
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int h_h = 1;
    for (int i = 1; i < N; i ++) {
        s[i] = get(i);
        s[i] += s[i - 1];
    }
    cin >> h_h;
    while (h_h--)solve();
    return 0;
}

F. Expected Median

思路:把 0 0 0和 1 1 1的个数统计出来,再至少保证有 ( k + 1 ) / 2 (k + 1) / 2 (k+1)/2个 1 1 1的前提下把 0 0 0和 1 1 1进行排列组合就行,记得取模

int fac[N], inf[N];

int ksm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = inf[0] = 1;
    for (int i = 1; i < N; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inf[i] = inf[i - 1] * ksm(i, mod - 2) % mod;
    }
}

int C(int n, int m) {
    return fac[n] * inf[m] % mod * inf[n - m] % mod;
}


void solve() {
    int n, k; cin >> n >> k;
    int c0 = 0, c1 = 0;
    for (int i = 1, x; i <= n; i ++) {
        cin >> x;
        if (x == 0) c0 ++;
        else c1 ++;
    }
    int zw = (k + 1) / 2;
    if (c1 < zw) {
        cout << 0 << '\n';
        return ;
    }
    int ans = 0;
    for (int i = zw; i <= c1 && i <= k; i ++) {
        if (c0 >= k - i) ans = (ans + C(c1, i) * C(c0, k - i) % mod) % mod;
    }
    cout << ans << '\n';
}

G1. Ruler (easy version)

思路: 询问至多 10 10 10次,数据范围 999 999 999,直接二分,注意交互题的格式就行

void solve() {
    int l = 1, r = 999, ans = -1;
    while (l <= r) {
        int mid = l + r >> 1;
        cout << '?' << ' ' << mid << ' ' << mid << endl;
        cout << endl;
        int s; cin >> s;
        if (mid * mid != s) r = mid - 1;
        else l = mid + 1, ans = mid;
    }
    cout << '!' << ' ' << ans + 1 << endl;
}

G2. Ruler (hard version)

思路: 询问至多 7 7 7次,数据范围 999 999 999,直接三分,注意交互题的格式就行,比赛时写拉了,哭泣

void solve() {
    int l = 1, r = 999;
    while (l < r) {
        int mid = l + r >> 1;
        int midl = l + (r - l) / 3;
        int midr = r - (r - l) / 3;
        cout << '?' << ' ' << midl << ' ' << midr << endl;
        int x; cin >> x;
        if (x == midl * midr) l = midr;
        else if (x == midl * (midr + 1)) l = midl, r = midr - 1;
        else r = midl - 1, ans = midl;
    }
    cout << '!' << ' ' << l + 1 << '\n';
}

标签:964,r1,r2,int,Codeforces,else,++,ans,Div
From: https://blog.csdn.net/weixin_73914071/article/details/140969557

相关文章

  • div-固定在页面中间,不被其他元素覆盖
    最开始设置的子元素D是text-align:center,子元素C的内容过长的时候,会发现子元素D不在页面正中了所以需要把子元素D设置成固定中间,把子元素D设置成固定中间后,发现元素B把子元素D给覆盖了一部分,所以需要在父元素A和元素B之间加一个空的div,给div设置高度后,父元素A和元素B之间的距离......
  • Codeforces 165E Compatible Numbers 题解
    思路高维前缀和高维前缀和把数的二进制看成一个集合,二进制的每一位为\(1\)为全集\(V\)。根据题目描述,若两数\(a,b\)相容,则\(a\operatorname{and}b=0\),容易发现,\(b\in\complement_{V}a\),所以我们只需要用高维前缀和处理出\(\complement_{V}a\)的一个元素即可。......
  • Codeforces Round 964 (Div. 4)
    知识点1.对于两个数字,一个乘n,一个除以n,可以理解为n进制下的这个数乘10和除10。比如E题用这个知识点就可以很快的解决问题。题解A.A+BAgain?#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;voidsolve(){ strings; cin>>s; cout<<s[0]-'0'+s[1]-......
  • Codeforces Round 964 (Div. 4)
    CodeforcesRound964(Div.4)A送分B大意:两个人两张牌随机翻求a翻出来的牌比b大的可能#include<cstdio>#include<cmath>#include<algorithm>#include<iostream>#include<cstring>#include<vector>#defineepemplace_backusingnamespace......
  • Codeforces Round 964 (Div. 4) D. Slavic's Exam
    题目链接:https://codeforces.com/contest/1999/problem/D题目描述Slavic的考试非常难,需要您的帮助才能通过。以下是他正在努力解决的问题:存在一个字符串s,它由小写英文字母和可能零个或多个“?”组成。Slavic被要求将每个“?”更改为小写英文字母,使得字符串t成为字符串s的......
  • Codeforces Round 962 (Div. 3)
    A.Legs-------------------------------------题解------------------------------经典鸡兔同笼,数据范围不大,跑暴力就行点击查看代码#include<bits/stdc++.h>usingnamespacestd;intmain(){intt;cin>>t;while(t--){intn;cin>......
  • 题解:Codeforces Round 964 (Div. 4) D
    D.Slavic'sExamtimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputSlavichasaverytoughexamandneedsyourhelpinordertopassit.Hereisthequestionheisstrugglingwith:Ther......
  • 题解:Codeforces Round 964 (Div. 4) C
    C.Showeringtimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputAsacomputersciencestudent,Alexfacesahardchallenge —showering.Hetriestoshowerdaily,butdespitehisbestefforts......
  • Codeforces Round 964 (Div. 4)
    比赛链接:CodeforcesRound964(Div.4)A思路    水题代码#include<iostream>usingnamespacestd;#definelllonglonginlineintread(void){intx=0,f=1;charch=getchar();while(ch<'0'||ch>'9'){......
  • 题解:Codeforces Round 964 (Div. 4) A
    A.A+BAgain?timelimitpertest:1secondmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputGivenatwo-digitpositiveinteger\(n\),findthesumofitsdigits.InputThefirstlinecontainsaninteger\(t\)(\(1......