Skip to content

Commit 602f09c

Browse files
committed
Added 1547A - Shortest Path with Obstacle.cpp
1 parent db8952a commit 602f09c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// ॐ नमः शिवाय
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
#define ll long long
6+
#define pb push_back
7+
#define ff first
8+
#define ss second
9+
#define mp make_pair
10+
11+
// Code Written By: Vikash Patel
12+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
13+
14+
int main()
15+
{
16+
ios_base::sync_with_stdio(0);
17+
cin.tie(0);
18+
cout.tie(0);
19+
20+
// #ifndef ONLINE_JUDGE
21+
// freopen("input.txt", "r", stdin);
22+
// freopen("/Users/vikash/Desktop/output.txt", "w", stdout);
23+
// #endif
24+
25+
int t;
26+
cin>>t;
27+
while(t--)
28+
{
29+
int xa, ya, xb, yb, xf, yf;
30+
cin>>xa>>ya>>xb>>yb>>xf>>yf;
31+
if(yb == ya && yb == yf && xf >= min(xa, xb) && xf <= max(xa, xb))
32+
cout<<2+abs(xb-xa)<<endl;
33+
else if(xb == xa && xb == xf && yf >= min(ya, yb) && yf <= max(ya, yb))
34+
cout<<2+abs(yb-ya)<<endl;
35+
else
36+
cout<<abs(yb-ya) + abs(xb-xa)<<endl;
37+
}
38+
return 0;
39+
}

0 commit comments

Comments
 (0)