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

题目链接


在这里插入图片描述
对于上图,我们枚举一下能够得到的所有答案:

1 + 2 + 4 + 8 + 13 = 28 {1+2+4+8+13=28} 1+2+4+8+13=28

1 + 2 + 5 + 8 + 13 = 29 {1+2+5+8+13=29} 1+2+5+8+13=29

1 + 2 + 5 + 9 + 13 = 30 {1+2+5+9+13=30} 1+2+5+9+13=30

1 + 3 + 5 + 8 + 13 = 30 {1+3+5+8+13=30} 1+3+5+8+13=30

1 + 3 + 5 + 9 + 13 = 31 {1+3+5+9+13=31} 1+3+5+9+13=31

1 + 3 + 6 + 9 + 13 = 32 {1+3+6+9+13=32} 1+3+6+9+13=32

那么我们发现有5个不同的答案,观察上面表格容易知道,从左上角先一直向右再一直向下得到的是最小值 28 28 28,先一直向下再一直向右得到的是最大值 32 32 32。由于对角线从右上到左下递增的性质,这中间的数刚好全部都能得到,那么答案就是最大值减最小值加一

但是我们无法计算出最大值和最小值,而不难发现我们最后的答案也只是需要二者的差值

因为最大值和最小值的第一个数和最后一个数都相同,那么我们考虑每个次对角线的右上和左下,二者刚好分别是最小值和最大值的一部分,那么对每个次对角线两头的数分别求差值,最后求和得到的就是最大值和最小值的差值,当然最后的答案还应加一

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <bitset>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define lowbit(x) (x&(-x))
#define mkp(x,y) make_pair(x,y)
#define mem(a,x) memset(a,x,sizeof a);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t;
    ll a,b,c,d;
    cin>>t;
    while(t--){
        cin>>a>>b>>c>>d;
        cout<<(d-b)*(c-a)+1<<"\n";
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值