Codeforces Round #731 (Div. 3) A. Shortest Path with Obstaclea
Posted yueshehanjiang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #731 (Div. 3) A. Shortest Path with Obstaclea相关的知识,希望对你有一定的参考价值。
A. Shortest Path with Obstacle
题意:
求从a点出发不经过f点到达b点的最短的曼哈顿距离
思路:
if特殊判断一下
当三个点横坐标相等的时候,f点是否在2点之间
或者是当三个点纵坐标相等的时候,f点是否在2点之间
如果是的话 说明不能走直线,距离要+2
否则就是a到b的曼哈顿距离
时间复杂度:O t
#include<bits/stdc++.h>
#define fer(i,a,b) for(re i = a ; i <= b ; ++ i)
#define re register int
#define pll pair<int,int>
#define x first
#define y second
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
typedef long long ll ;
using namespace std;
const int N = 1e6 + 10 , M = 1010 , inf = 0x3f3f3f3f , mod = 1e9 + 7 ;
int main()
{
int t ;
cin >> t ;
while(t--)
{
int a , b , c , d , e , f ;
cin >> a >> b >> c >> d >> e >> f ;
// e >= min(a,c) && e <= max(a,c)
// f >= min(b,d) && f <= max(b,d)
if(a == c && a == e && f >= min(b,d) && f <= max(b,d) || b == d && b == f && e >= min(a,c) && e <= max(a,c))
{
cout << abs(a - c) + abs(b - d) + 2 << "\\n" ;
}
else
{
cout << abs(a - c) + abs(b - d) << "\\n" ;
}
}
return 0;
}
以上是关于Codeforces Round #731 (Div. 3) A. Shortest Path with Obstaclea的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #731 (Div. 3)
Codeforces Round #731 (Div. 3) E题解
Codeforces Round #731 (Div. 3) B. Alphabetical Strings
Codeforces Round #731 (Div. 3) E. Air Conditioners
Codeforces Round #731 (Div. 3) F. Array Stabilization (GCD version)
Codeforces Round #731 (Div. 3) F. Array Stabilization (GCD version)