牛客周赛 Round 6

Ke_scholar / 2023-08-07 / 原文

牛客周赛 Round 6

A-游游的数字圈_牛客周赛 Round 6 (nowcoder.com)

枚举即可

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

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0;i < s.size();i ++){
        ans += (s[i] == '0' || s[i] == '6' || s[i] == '9');
        ans += (s[i] == '8') * 2;
    }
    
    cout << ans << '\n';
    return 0;
}

B-竖式乘法_牛客周赛 Round 6 (nowcoder.com)

\(a\)每次去乘\(b\)的每一位数累加即可

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

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int ans = 0;
        int a,b;
        cin >> a >> b;

        while(b){
            ans += b % 10 * a;
            b /= 10;
        }

        cout << ans << '\n';
    }
    return 0;
}

C-游游的数值距离_牛客周赛 Round 6 (nowcoder.com)

若令\(|x! \times y - y - n|=0\),我们可以得到\(y = \frac{n}{x! - 1}\),因此我们可以去枚举\(x\),从而得到\(y\),且这里是向下取整的,所以正确答案要么是 \(y\) 要么是 \(y+1\) ,又因为\(x!\)是一个很大的数,所以我这里枚举到\(10\)就行了

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

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    int ansx = 1,ansy = 1,fac = 2,ans = n;
    for(int i = 3;i <= 10;i ++){
        fac *= i;

        int y = n / (fac - 1);
        int val = abs(y * (fac - 1) - n);
        if(y > 0 && y != 2 && val <= ans){
            ans = val, ansx = i, ansy = y;
        }

        y++;
        val = abs(y * (fac - 1) - n);
        if(y > 0 && y != 2 && val <= ans){
            ans = val, ansx = i, ansy = y;
        }
    }

    cout << ansx << ' ' << ansy << '\n';

    return 0;
}

D-游游的k-好数组_牛客周赛 Round 6 (nowcoder.com)

要使得所有长度区间为\(k\)的区间和相等,最简单的方法就是让每隔\(k\)个数字相等,这样每长度为\(k\)的第\(i\)个数字都相同,那自然区间和也相等,所以我们先算出每隔\(k\)个数字的最大值,然后计算每\(k\)个数字到其最大值差多少,我们最多补\(x\),如果说差的比我们能补得还多,那我们不能把它变为一个\(k-\)好数组,否则我们尽量的把多出来的数分到所有的长度为\(k\)的区间内的第\(i\)个数字上,最后就是看分配到哪个位置上能得到最大值

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

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int n,k,x;
        cin >> n >> k >> x;
        vector<int> a(n),mx(k);
        for(int i = 0;i < n;i ++){
            cin >> a[i];
            mx[i % k] = max(mx[i % k], a[i]);
        }

        int sum = 0;
        for(int i = 0;i < n;i ++)
            sum += mx[i % k] - a[i];

        if(sum > x){
            cout << -1 << '\n';
            continue;
        }

        x -= sum;
        int ans = 0;
        for(int i = 0;i < k;i ++){
            int now = n / k + (n % k > i);
            ans = max(ans, mx[i] + x / now);
        }

        cout << ans << '\n';

    }

    return 0;
}

E-小红的循环节长度_牛客周赛 Round 6 (nowcoder.com)

后面补题了再写题解qwq