传送门:洛谷 CF2148B Lasers | Codeforces B. Lasers
更佳的阅读体验:CF2148B 题解
简要题意:有 $n$ 条水平激光和 $m$ 条垂直激光,问从 $(0, 0)$ 到 $(x, y)$ 最少需要穿过多少条激光。
所有水平激光都落在 $[1, y - 1]$ 区间内,所有垂直激光都落在 $[1, x - 1]$ 区间内。我们发现,不论怎么走,我们必须要穿过每条激光至少一次。
直接输出 $n + m$ 即可。
#include <iostream>
using namespace std;
const int N = 2e5 + 10;
int t, n, m, x, y, a[N], b[N];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
for (cin >> t; t; --t) {
cin >> n >> m >> x >> y;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= m; ++i) cin >> b[i];
cout << n + m << '\n';
} return 0;
}