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 级开源代码模型系列,包括基础变体、指导变体和推理变体,由字节团队开源

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值