forked from opencodeiiita/CodeDigger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencodeiiita#108 from Goddbott/main
Create Problem
- Loading branch information
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Explanation: | ||
|
||
https://drive.google.com/file/d/11H9PEmoWNaFNNrrQ6WS2Oof5cvMt1CeR/view?usp=sharing | ||
|
||
First we calculate the difference between the coordinates of starting point and ending point. | ||
a= X2-X1 and b=Y2-Y1 | ||
|
||
One can observe that if a is greater than b or any of a or b is negative then it is impossible to reach the ending point. | ||
If a is equal to b then one can directly move diagonally to reach the ending point in minimum time. | ||
If a is less than b then we first move diagonally then move up to reach the ending point in minimum time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<bits/stdc++.h> | ||
#define int long long | ||
using namespace std; | ||
int32_t main(){ | ||
int t; | ||
cin>>t; | ||
while(t--){ | ||
int m,n; | ||
cin>>m>>n; | ||
int x1,y1,x2,y2; | ||
cin>>x1>>y1>>x2>>y2; | ||
int a= x2-x1; | ||
int b= y2-y1; | ||
if (a<0 || b<0 || a>b){ | ||
cout<<-1<<endl; | ||
continue; | ||
} | ||
else if (a==b){ | ||
cout<<a<<endl; | ||
} | ||
else if (b>a){ | ||
cout<<a+(y2-(y1+a))<<endl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
You are given a grid of width m and length n. The grid is made up of m*n boxes of dimensions 1*1. You are given a starting point (x1,y1) and an ending point (x2,y2). | ||
You are only allowed to move 1 unit diagonally and 1 unit up. Every move by one unit takes 1 second. Find the minimum time it would take to reach the destination. If it is not possible then output -1.The problem contains T test cases. | ||
|
||
Input Format: | ||
The first line contains an integer T denoting the number of test cases. | ||
In each test case | ||
The first line contains integers m,n denoting the width and length of the grid. | ||
The second line contains integers x1,y1 and x2,y2 denoting the starting and ending points. | ||
|
||
Output: | ||
Print the minimum time taken to reach the destination in a single line. If not possible then print -1.3 | ||
|
||
Constraints: | ||
1<= T <= 10^5 | ||
1<= m,n <= 10^9 | ||
1<= x1,x2 <= m | ||
1<= y1,y2 <= n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Input: | ||
2 | ||
8 9 | ||
1 2 5 6 | ||
8 9 | ||
1 2 8 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
4 | ||
-1 |