比赛链接: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;
}
1154

被折叠的 条评论
为什么被折叠?



