AtCoder Beginner Contest 377
A - Rearranging ABC#
题意#
给长度为
的字符串问是不是
思路#
模拟。
代码#
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int cnt[30] = { 0 };
for (int i = 0; i < 3; i++)
{
char c;
cin >> c;
cnt[c - 'A']++;
}
if (cnt[0] == 1 && cnt[1] == 1 && cnt[2] == 1)
{
cout << "Yes" << endl;
return;
}
cout << "No" << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
B - Avoid Rook Attack#
题意#
的网格,"."表示空,"#"表示有棋子,每个棋子能攻击它所在行和列的所有格子。找出不会被攻击的格子数。
思路#
怎么做都行。
代码#
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
bool r[10], c[10];
void solve()
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
char ch;
ch = getchar();
if (ch == '#')
{
r[i] = c[j] = true;
}
}
getchar();
}
int ans = 0;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (!r[i] && !c[j])
{
ans++;
}
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
C - Avoid Knight Attack#
题意#
思路#
用
存能攻击的坐标,答案就是 。
代码#
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int mxn = 2e5 + 5;
int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
int n, m, x, y;
set<pii> vis;
void solve()
{
cin >> n >> m;
for (int i = 0; i < m; i++)
{
cin >> x >> y;
vis.insert({ x,y });
for (int j = 0; j < 8; j++)
{
int tx = x + dx[j];
int ty = y + dy[j];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= n)
{
vis.insert({ tx, ty });
}
}
}
cout << n * n - vis.size() << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
D - Many Segments 2#
题意#
给定两个长度为
的序列,以及整数 ,求满足以下两个条件的整数对 的个数:
对于每个来说,区间 并不完全包含区间
思路#
代码#
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
void solve()
{
int n, m;
cin >> n >> m;
vector<int> d(m + 1, 1);
for (int i = 0; i < n; i++)
{
int l, r;
cin >> l >> r;
d[r] = max(d[r], l + 1);
}
for (int r = 1; r <= m; r++)
{
d[r] = max(d[r], d[r - 1]);
}
int ans = 0;
for (int r = 1; r <= m; r++)
{
ans += r - d[r] + 1;
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
E - Permute K times 2#
题意#
给定
的排列 ,进行 次操作:使 。求最终序列。
思路#
代码#
点击查看代码
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】