题目大意:
给你一个图,要求从
(
x
1
,
y
1
)
(x_1,y_1)
(x1,y1) 走到
(
x
2
,
y
2
)
(x_2,y_2)
(x2,y2),只能向左或下,然后得到所走路径上的数之和,问一共有多少种和。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c656c1e2f3f9255d5decc57e6cfd6e37.png)
思路:
- 我们可以很容易知道,路径和最大的是先一直向下在一直向右,记 maxn,路径和最小的是先一直 向下一直 向左,记 minn。
- 考虑 x=minn+1,是可以通过 minn 的方案少走一次向右多一次向下得到。依此类推一直得到 maxn 。
-
结论:对于 ∀ x,当 x
∈
\in
∈[minn,maxn] 都可以得到,所以 ans=maxn-minn+1。
- 至于manx与minn之差通过观察图是可以容易发现就是 abs(x1-x2)*abs(y1-y2)+1;
input:
4
1 1 2 2
1 2 2 4
179 1 179 100000
5 7 5 7
output:
2
3
1
1
code:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define Please return
#define Accepted 0
#define int long long
#define endl "\n"
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double, double> PDD;
const int N = 200010,M=2*N,INF=0x3f3f3f3f;
int n;
void slove(int _case)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int ans = (x1-x2)*(y1-y2)+1;
cout<<abs(ans)<<endl;
}
signed main()
{
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
for(int _case=1;_case<=T;_case++)
{
slove(_case);
}
Please Accepted;
}