C. Celex Update
题目大意:给出两点的坐标,找出不同的路径的总数(路径数字总和不同)
思路:根据观察向下走比向右走的增加幅度加1,所以在第i步 向下 对sum的影响是 n-i+1
所以最小数字为1+2+。。。。+y;
最大数字最大就是n+n-1+n-2+。。。+n-y;
我的代码:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#define INF 0x3f3f3f3f
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define re register
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(a) ((a)&-(a))
#define ios std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define fi first
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define se secondusing namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int > pii;
const ll mod=10001;
const ll N =2e5+10;
const double eps = 1e-4;
//const double pi=acos(-1);
ll gcd(int a,int b){return !b?a:gcd(b,a%b);}
int dx[4]={-1,0,1,0} , dy[4] = {0,1,0,-1};
int a[N];
void solve()
{int x1,x2,y1,y2;cin>>x1>>y1>>x2>>y2;if(x1==x2||y1==y2) cout<<"1\n";else{int x=abs(x1-x2);int y=abs(y1-y2);ll k=x+y;ll any=(k-y)*y;cout<<any+1<<"\n";}
}
int main()
{int T;cin>>T;while(T--){solve();}return 0;
}
其实公式 可以整合为 x*y+1;
#include<bits/stdc++.h>
using namespace std;
int main()
{int t;cin>>t;while(t--){long long int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;cout<<(x2-x1)*(y2-y1)+1<<endl;}
}