Codeforces Round #645 (Div. 2)-C - Celex Update(思维)

题目链接
题意:
给你一个由顺序的数字斜向摆放而成的方阵,求从矩阵的(x1,y1)点到(x2,y2)点所经过的路程的数字相加一共能有多少种不同的结果(期间只能向右或向左走)。
思路:
求路程数字最大值和最小值的差就是结果,因为是顺序数字斜向摆放,所以横向与竖向数字之间的差值刚好是abs(x1-x2)和abs(y1-y2),所以答案就是abs(x1-x2)*abs(y1-y2)+1。
代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e5+5;
const int inf=0x3f3f3f3f;
int cmp(int a,int b)
{
    return a<b;
}
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x1,x2,y1,y2;
        cin>>x1>>y1>>x2>>y2;
        cout<<abs(x1-x2)*abs(y1-y2)+1<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ACkingdom/article/details/106388256