牛客周赛 Round 76题解(ABC)

比赛链接:牛客周赛 Round 76

A-小红出题

思路:模拟即可。

#include <bits/stdc++.h>
#include <unordered_set>
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define LL long long
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
using namespace std;

int n;

int main()
{
    IOS;
    cin >> n;
    int a = (n / 7) * 15;
    int b = 0;
    if(n%7<=5)
        b = (n % 7) * 3;
    else
        b = 5 * 3;
    cout << a + b;
    return 0;
}

B-串串香

思路:贪心的思想,显然越短的子串出现的次数可能越多,而最短的子串就是单个的字符,故只需要统计出现最多的字符是什么即可。

#include <bits/stdc++.h>
#include <unordered_set>
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define LL long long
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
using namespace std;

int n;
string s;
int num[100005];

int main()
{
    cin >> n >> s;
    rep(i,0,s.size()-1)
    {
        num[s[i] - 'a']++;
    }
    int maxn = 0;
    char ans;
    rep(i,0,25)
    {
        if(num[i]>maxn)
        {
            maxn = num[i];
            ans = (char)('a' + i);
        }
            
    }
    cout << ans;
    return 0;
}

C-小红的gcd

思路:我们知道gcd(a,b)<=min(a,b),贪心地思考,任意次操作后数组的最小值,就等于整个数组所有数的gcd。记得开long long。

#include <bits/stdc++.h>
#include <unordered_set>
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define LL long long
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
using namespace std;

int n;
int a[100005];

LL gcd(LL a, LL b)
{
    while (b != 0)
    {
        LL temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

int main()
{
    cin >> n;
    rep(i, 1, n)
    {
        cin >> a[i];
        
    }
    LL agcd = a[1];
    rep(i,1,n)
    {
        agcd = gcd(agcd, a[i]);
    }
    cout << agcd * n;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值