【LABOI 2026】过客 / guest 题解
__biu_biu_biu__ · · 题解
出题人题解。
为了方便,我们先特判小 Z 一开始在小 C 的视野范围内的情况。
先计算出小 Z 走到小 C 视野范围内的答案,为
此时我们可以得到小 Z 剩下可以走的步数
注意特判
:::info[代码]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
ll x, y, s, t, k, l;
cin >> x >> y >> s >> t >> k >> l;
ll dis = abs(x - s) + abs(y - t);
if(dis <= k) {//特判一开始小 Z 就在小 C 视野范围内的情况
if(k == 0) cout << l / 2 << '\n';
else cout << l << '\n';
continue ;
}
l -= (dis - k);//剩余步数
if(l < 0) {
cout << 0 << '\n';
continue ;
}
if(k == 0) {
cout << 1 + l / 2 << '\n';
}
else cout << 1 + l << '\n';//注意添加一开始走到视野范围内时的 1 贡献
}
return 0;
}
:::