A - Secret Numbers
题目大意
给你一个字符串 ,删除掉其中非数字字符,输出新字符串。
思路
与其删除非数字字符,不如只输出数字字符。
代码
/*
* @FilePath: \c++\ABC462A.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:40:22
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
string s;
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> s;
for (auto i : s)
if (i >= '0' && i <= '9')
cout << i;
return 0;
}B - Gift
题目大意
编号为 至 的 个人互相送礼物,第 个人分别向第 个人送礼物,输出每个人收到的礼物个数以及都有谁给他送礼物。
思路
按照题意模拟即可。
代码
/*
* @FilePath: \c++\ABC462B.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:40:57
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, k, a;
vector<int> mp[105];
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> k;
for (int j = 1; j <= k; j++)
cin >> a, mp[a].push_back(i);
}
for (int i = 1; i <= n; i++)
{
cout << mp[i].size() << " ";
for (auto j : mp[i])
cout << j << " ";
cout << "\n";
}
return 0;
}C - Not Covered Points
题目大意
给出 个点的坐标 ,其中 均为 的排列,求“在其左下方没有点”的点的个数(因为是排列所以不用考虑边界情况)。
思路
将点按照横坐标升序排序,从左到右对于每个点看在其之前是否有纵坐标比它小的点,如果没有则答案加一。
用 set 维护即可。
代码
/*
* @FilePath: \c++\ABC462C.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:41:04
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Node
{
int x, y;
bool operator<(const Node &a) const { return this->x < a.x; }
} a[300005];
int n, ans;
set<int> st;
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
{
auto it = st.upper_bound(a[i].y);
if (it == st.begin())
ans++;
st.insert(a[i].y);
}
cout << ans;
return 0;
}D - Accomplice
题目大意
一场犯罪有 个嫌疑人,第 个嫌疑人在时间 进入房间,在时间 离开房间。
这场犯罪有两名罪犯,持续时间为 ,期间两名罪犯都要在房间内(两个临界时间点也被认为在房间内),求两名罪犯和犯罪开始时间有多少种可能组合。
思路
刚开始题读错了(翻译的锅),认为是罪犯的组合数,吭哧半天写了个带 tag 的线段树然后发现样例过不了。
对于每一个人来说,如果 ,那么他不可能犯罪,否则他犯罪开始时间点的范围为 。
用差分维护每个人犯罪开始时间点的范围,然后对于每个时间点,如果有 个人可能开始犯罪,那么其对答案的贡献为 。
代码
/*
* @FilePath: \c++\ABC462D.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:41:12
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((l + r) >> 1)
int n, d, s, t, ans, cf[1000005], sum;
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> d;
for (int i = 1; i <= n; i++)
{
cin >> s >> t;
if (t - s >= d)
cf[s]++, cf[t - d + 1]--;
}
for (int i = 1; i <= 1000000; i++)
sum += cf[i], ans += sum * (sum - 1) / 2;
cout << ans;
return 0;
}E - Alternating Costs
题目大意
次询问,每次询问如下:
给出一个点 和 ,进行若干次操作使得一枚棋子从 移动到 。
对于第 次操作:
- 如果 是奇数,那么向左或向右移动的代价为 ,向上或向下移动的代价为 。
- 如果 是偶数,那么向左或向右移动的代价为 ,向上或向下移动的代价为 。
求从 移动到 所需的最小代价。
思路
首先向上走和向下走是一样的,向左走和向右走是一样的,所以先对坐标取绝对值。
为了方便计算,我们假设 ,如果不满足则交换 同时交换 。
显然是最好的(略微不准确,一些加一减一的情况也可以),一直用 走即可。如果 ,那么有两种走法,一种是横向先走满 ,剩下的 只能 和 交替;另一种是通过纵向多走几次,使得代价一直是 ,大概就像长城那种样子。 同理。
得到的两种总代价取小者即可,具体实现细节请看代码。
代码
/*
* @FilePath: \c++\ABC462E.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:41:20
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
int t, a, b, x, y;
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> t;
while (t--)
{
cin >> a >> b >> x >> y, x = max(x, -x), y = max(y, -y);
if (a > b)
swap(a, b), swap(x, y);
int num = max(y * 2, x * 2 - 1);
num += num % 2 != (x + y) % 2;
cout << min((x + y) * a + (b - a) * ((x + y) - min(x, (x + y + 1) / 2) - min(y, (x + y) / 2)), num * a) << "\n";
}
return 0;
}