模拟题
https://atcoder.jp/contests/abc421/tasks/abc421_d
按相对位移去处理两个人的移动可以简化模拟难度
#include <bits/stdc++.h>
#define nmf(i, s, e) for (int i = s; i <= e; i++)
#define ref(i, s, e) for (int i = s; i >= e; i--)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
int main()
{
pair<int, int> mp[4];
mp[0] = {0, -1}, mp[1] = {0, 1}, mp[2] = {-1, 0}, mp[3] = {1, 0};
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
LL rt, ct, ra, ca;
cin >> rt >> ct >> ra >> ca;
ra -= rt;
ca -= ct;
rt = ct = 0;
LL n, m, l;
cin >> n >> m >> l;
deque<pair<int, LL>> a, b;
nmf(i, 1, m)
{
char c;
LL cnt;
cin >> c >> cnt;
a.push_back({(c == 'L' ? 0 : c == 'R' ? 1
: c == 'U' ? 2
: 3),
cnt});
}
nmf(i, 1, l)
{
char c;
LL cnt;
cin >> c >> cnt;
b.push_back({(c == 'L' ? 0 : c == 'R' ? 1
: c == 'U' ? 2
: 3),
cnt});
}
LL ans = 0;
while (!a.empty() || !b.empty())
{
int dt = a.front().first;
LL la = a.front().second;
int da = b.front().first;
LL lb = b.front().second;
a.pop_front();
b.pop_front();
LL len = min(la, lb);
if (la > lb)
{
a.push_front({dt, la - len});
}
else if (la < lb)
{
b.push_front({da, lb - len});
}
LL d1 = mp[da].first - mp[dt].first;
LL d2 = mp[da].second - mp[dt].second;
LL step = -1;
if (rt == ra && ct == ca)
{
if (dt == da)
ans += len;
}
else if (ra || ca)
{
if (d1 != 0)
step = -ra / d1;
if (d2 != 0)
step = -ca / d2;
if (step > 0 && step <= len && d1 * step == -ra && d2 * step == -ca)
ans++;
}
ra += d1 * len;
ca += d2 * len;
}
cout << ans << endl;
return 0;
}

浙公网安备 33010602011771号