牛客周赛 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;
}

### 关于周赛 Round 80 的相关信息 目前并未找到具体针对周赛 Round 80 的官方题解或比赛详情文档。然而,基于以往的比赛模式和惯例[^1],可以推测出此类赛事通常包含若干算法题目,覆盖基础数据结构、动态规划、贪心策略以及图论等领域。 #### 可能涉及的内容范围 1. **签到题 (A 题)** 这类题目一般较为简单,旨在测试选手的基础编程能力。例如简单的数学计算或者字符串处理问题。 2. **中级难度题 (B 到 D 题)** 中级难度的题目往往需要一定的算法设计能力和复杂度分析技巧。比如: - 动态规划优化问题; - 贪心算法的应用场景; - 图遍历与最短路径求解; 3. **高阶挑战题 (E 或更高)** 对于更复杂的题目,则可能涉及到高级的数据结构操作(如线段树、并查集)、组合数学推导或者其他领域内的难题解决方法。 以下是根据过往经验给出的一个假设性的例子来展示如何解答类似的竞赛问题: ```python def solve_example_problem(n, m): """ 假设这是一个关于矩阵填充的问题, 给定 n 行 m 列大小的空间,按照某种规则填充值。 参数: n -- 矩阵行数 m -- 矩阵列数 返回值: result_matrix -- 完成后的二维列表形式的结果矩阵 """ # 初始化结果矩阵为全零状态 result_matrix = [[0]*m for _ in range(n)] value_to_fill = 1 direction_changes = [(0,1),(1,0),(0,-1),(-1,0)] # 方向变化顺序:右->下->左->上 current_direction_index = 0 row,col=0,0 while True: try: if not(0<=row<n and 0<=col<m): raise IndexError() if result_matrix[row][col]==0: result_matrix[row][col]=value_to_fill value_to_fill+=1 next_row,next_col=row+direction_changes[current_direction_index%len(direction_changes)][0],\ col+direction_changes[current_direction_index%len(direction_changes)][1] if any([not(0<=next_row<n), not(0<=next_col<m), bool(result_matrix[next_row][next_col])]): current_direction_index +=1 else: row,col=next_row,next_col except Exception as e: break return result_matrix if __name__ == "__main__": test_result=solve_example_problem(4,5) for line in test_result: print(line) ``` 上述代码片段展示了如何通过模拟实现一个螺旋状填充整数值至指定尺寸矩形中的过程作为示范案例之一[^4]。 ####
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值