昨天的cf题,差点因为这道题翻车了,幸好后面力挽狂澜XD。
一看这道题,一猜,路径上的数值之和肯定都是不同的,一写,自信一交,等待1a,wa on pretest 2,gnls,然后找了15分钟规律猜了个结论过了。
题解的思路是这样的:
把他想象成一个(借用cf tutorial里的图)这个样子的一个东西,初始状态是路径的和最小的那个状态,你要做的只是每次把他右上角的那个角给他按下去,就是把路径的和增加了,这样就能保证没有重复,可以看出答案就是 dx * dy + 1。
#include <bits/stdc++.h>
#define i64 long long
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
cin >> tc;
while (tc--) {
cin >> x1 >> y1 >> x2 >> y2;
i64 dx = x2 - x1;
i64 dy = y2 - y1;
i64 ans = dx * dy + 1;
cout << ans << '\n';
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}