ABC389题解(ABC)

部署运行你感兴趣的模型镜像

比赛链接:Toyota Programming Contest 2025(AtCoder Beginner Contest 389)

A - 9x9

思路:模拟即可。

#include <bits/stdc++.h>
#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 main()
{
    IOS;
    string s;
    cin >> s;
    cout << (s[0] - '0') * (s[2] - '0');
    return 0;
}

B - tcaF

思路:模拟即可,记得开long long。

#include <bits/stdc++.h>
#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;

LL x;

int main()
{
    IOS;
    cin >> x;
    LL pro = 1;
    int i = 1;
    while(pro < x)
        pro *= ++i;
    if(pro==x)
        cout << i;
    else
        cout << -1;
    return 0;
}

C - Snake Queue

思路:观察发现,每次需要输出第 k 条蛇的长度的时候,其实就是要求前 k-1 条蛇的长度和( k 为1 时即输出 0 ),我们可以通过维护一个前缀和来轻易地求出。具体地,我们通过维护两个指针 f 和 b 来描述队列的首尾,插入新的第 b-f+1 条蛇时让 b++ ,并用新蛇的长度 l 更新此位的前缀和 (注意,前缀和的第一项是 0 ),删除蛇时,我们让 f++, 查询第 k 条蛇时,通过 pres[f+k-1]-pres[f] 求出前 k-1 条蛇的长度和。

#include <bits/stdc++.h>
#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 Q;
LL pres[300005];

int main()
{
    IOS;
    cin >> Q;
    pres[1] = 0;
    int f = 1, b = 2;
    while (Q--)
    {
        int n;
        cin >> n;
        if (n == 1)
        {
            int l;
            cin >> l;
            pres[b] = pres[b - 1] + l;
            b++;
        }
        else if (n == 2)
            f++;
        else if (n == 3)
        {
            int k;
            cin >> k;
            cout << pres[f + k - 1] - pres[f] << endl;
        }
    }
    return 0;
}

您可能感兴趣的与本文相关的镜像

Seed-Coder-8B-Base

Seed-Coder-8B-Base

文本生成
Seed-Coder

Seed-Coder是一个功能强大、透明、参数高效的 8B 级开源代码模型系列,包括基础变体、指导变体和推理变体,由字节团队开源

目前提供的引用内容并未提及关于 ABC303 题目的具体解答或解析。然而,可以从一般性的角度出发,探讨可能涉及的算法分析方法以及常见的解题思路。 ### 关于算法分析的目的 算法分析的主要目的是评估其性能并寻求改进的可能性[^1]。这通常涉及到时间复杂度和空间复杂度两方面的考量。对于任何题目而言,理解这两者之间的权衡关系至关重要。 ### 动态规划的应用场景 如果 ABC303 的题目属于优化类问题,则可以考虑采用动态规划的方法解决。动态规划的核心在于通过子问题分解的方式减少重复计算,从而提高效率[^2]。例如,在某些路径规划或者资源分配问题中,动态规划能够显著降低时间复杂度。 ### 特殊数值处理技巧 - 俄式乘法 当遇到需要高效完成大量数值运算的情况时,类似于俄式乘法这样的技术可能会被引入作为解决方案之一[^3]。尽管它看起来较为基础,但在特定条件下却能发挥重要作用。 ### 安全编码实践中的注意事项 最后值得注意的是,在实际编写代码过程中还需要关注安全性方面的要求。比如防止潜在漏洞利用等问题发生[^4]。 由于缺乏针对ABC303的具体描述信息,上述仅为基于现有资料所做的推测性讨论。 若要获得更精确的答案,请提供更多细节说明。 ```python # 示例伪代码展示如何应用动态规划解决问题 def dp_solution(input_data): memo = {} # 创建记忆表存储中间结果 def helper(subproblem): if subproblem not in memo: result = some_recursive_logic(subproblem) memo[subproblem] = result return memo[subproblem] final_result = helper(initial_state_of_problem) return final_result print(dp_solution(example_input)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值