AtCoder ABC 249

本文介绍了四道编程竞赛题目,涉及字符串处理、搜索算法、排列组合及比例计算。第一题要求计算跑步速度,第二题检查字符串是否完美,第三题通过深度优先搜索找最大字符数,第四题寻找满足特定比例的数组三元组。通过对这些问题的解析,展示了编程思维和算法在解决实际问题中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A Jogging

没看清楚题 a不是移速 所以卡了十分钟 语法题

int main()
{
    int a, b, c, d, e, f, x;
    cin >> a >> b >> c >> d >> e >> f >> x; // 速度 b 和 e
    int aa1 = b * a, bb1 = e * d;
    
    int res1 = aa1 * (x / (a + c));
    int t = x % (a + c);
    if(t >= a)   res1 += aa1;
    else res1 += b * t;
    
    int res2 = bb1 * (x / (d + f));
    t = x % (d + f);
    if(t >= d)   res2 += bb1;
    else    res2 += e * t; 
    
    if(res1 > res2)
        puts("Takahashi");
    else if(res2 > res1)
        puts("Aoki");
    else
        puts("Draw");
    return 0;
}

B Perfect String

语法题 略

int main()
{
    map<int, int> mp;
    string s;
    cin >> s;
    bool ok = true;
    int n = s.size();
    rep(i, 0, n)
        mp[s[i] - 'a'] ++;
    for(auto x : mp)
        if(x.second > 1)
            ok = false;
 
    int da = 0, xiao = 0;
    rep(i, 0, n)
    {
        if(s[i] <= 'Z' && s[i] >= 'A')  da ++;
        if(s[i] <= 'z' && s[i] >= 'a')  xiao ++;
    }
    if(da == 0 || xiao == 0)  ok = false;
    if(ok)  puts("Yes");
    else puts("No");
}

C Just K(dfs)

任意选择的字符串 请问他们中的个数为k的字符 数量的最大值

简单搜索题 对于每一个字符串 可以选或者不选 dfs一下 注意代码实现

int n, k;

int dfs(vector<string> &a, vector<string> chosen, int idx)
{
    if(idx == a.size()) //当从所有字符串里选过之后
    {
        map<char, int> cnt;
        for(auto it : chosen) //加起来
        {
            rep(i, 0, (int)it.size())
                cnt[it[i]] ++;
        }
        int res = 0;
        for(auto it : cnt)
            if(it.second == k)   res ++;
        return res;
    }
 
    //搜索 要求最大值
    int a1 = dfs(a, chosen, idx + 1); //不选
    chosen.pb(a[idx]);
    int a2 = dfs(a, chosen, idx + 1); //选
    return max(a1, a2);
}

int main()
{
    cin >> n >> k;
    vector<string> a(n), b;
    rep(i, 0, n)
        cin >> a[i];
    
    cout << dfs(a, b, 0);
}

D Index Trio(排列组合)

给定数组A 取一个三元组**(i, j, k)** 要求满足a_i / a_j = a_k

这题被我读假了( 需要考虑到一种情况 a_i = 1 且 j = k

处理约数即可

eg 1 8 8
(1, 2, 2)
(1, 3, 3)
(1, 2, 3)
(1, 3, 2)
i的位置跟j颠倒 x2
== 8
(1, 1, 1) +1
res = 9
    由此可得核心代码
    rep(i, 0, n)
        cnt[a[i]] ++;
    
    LL res = 0;
    rep(i, 0, n)
    {
        for(int j = 1; j <= a[i] / j; j ++)
        {
            if(a[i] % j == 0)
            {
                res += 1LL * cnt[j] * cnt[a[i] / j];
                if(j * j != a[i])    
                    res += 1LL * cnt[j] * cnt[a[i] / j];
            }
        }
    }
关于 AtCoder Beginner Contest 387 的信息如下: ### 关于 AtCoder Beginner Contest 387 AtCoder Beginner Contest (ABC) 是一项面向编程爱好者的定期在线竞赛活动。对于 ABC387,该赛事通常会在周末举行,并持续大约100分钟,在此期间参赛者需解决一系列算法挑战问题。 #### 比赛详情 - **举办平台**: AtCoder Online Judge System[^2] - **比赛时间长度**: 大约为1小时40分钟 - **难度级别**: 初学者友好型,适合那些刚开始接触竞争性程序设计的人群参与 - **题目数量**: 一般情况下会提供四到六道不同难度级别的题目供选手解答 #### 题目概览 虽然具体细节可能因官方发布而有所变化,但可以预期的是,这些题目将会覆盖基础的数据结构、字符串处理以及简单图论等方面的知识点。每一道题目的描述都会清晰给出输入输出格式说明及样例测试数据以便理解需求并验证解决方案的有效性。 为了获取最准确的比赛时间和确切的题目列表,请访问 [AtCoder 官方网站](https://atcoder.jp/) 并查看最新的公告板或直接导航至对应编号的具体页面来获得更新的信息。 ```python import requests from bs4 import BeautifulSoup def get_contest_info(contest_id): url = f"https://atcoder.jp/contests/{contest_id}" response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') title_element = soup.find('title') problem_list_elements = soup.select('.panel.panel-default a[href^="/contests/{}/tasks"]'.format(contest_id)) contest_title = title_element.string.strip() if title_element else "Contest Title Not Found" problems = [element['href'].split('/')[-1] for element in problem_list_elements] return { "name": contest_title, "problems": problems } else: raise Exception(f"Failed to fetch data from {url}") abc_387_details = get_contest_info("abc387") print(abc_387_details) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值