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

题目链接:C、Celex Update

题意:

给你如图所示的图形,问从(x1,y1)−>(x2,y2)路径上的不同的元素和的数量是多少。

题解:

从(1,1)到(3,3)

元素和的1−2−4−8−13是这些元素和中最小的一个,然后1−2−5−8−13和之前的一个相比多了1,在2处增加一个的话,那么就是1−3−5−8−13这就是增加了两个的了,最后我们可以发现从最小的元素和到最大的元素中全部的都会出现,那么就是计算中间的差值

 这几个块,每多用一个,就比之前的多加1

代码:

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string>
#include<queue>
#include<deque>
#include<string.h>
#include<map>
#include <iostream>
#include <math.h>
#define Mem(a,b) memset(a,b,sizeof(a))
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double eps=1e-6;
const double PI=acos(-1);
const int mod=998244353;
const int maxn=1e5+10;
ll gcd(ll m, ll n)
{
    return n == 0 ? m : gcd(n, m % n);
}
ll lcm(ll m, ll n)
{
    return m * n / gcd(m, n);
}
int main()
{
    ll T;
    cin >> T;
    while (T--)
    {
        ll x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        cout << (x2-x1)*(y2-y1)+1<< endl;;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/13361846.html