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

文章描述了一个编程竞赛中的问题,要求在给定的图形中找出从(x_1,y_1)到(x_2,y_2)的所有路径中数字之和的最大值和最小值,并计算不同和的路径数量。解决思路涉及找到最大和最小路径和,然后确定所有可能的和值范围。代码示例展示了如何计算这个范围并输出答案。
摘要由CSDN通过智能技术生成

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

题目大意:

给你一个图,要求从 ( x 1 , y 1 ) (x_1,y_1) (x1,y1) 走到 ( x 2 , y 2 ) (x_2,y_2) (x2,y2),只能向左或下,然后得到所走路径上的数之和,问一共有多少种和。

在这里插入图片描述

思路:

  • 我们可以很容易知道,路径和最大的是先一直向下在一直向右,记 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值