Skip to content

Commit a8891a3

Browse files
Merge branch 'main' into add-contributor-adityashirsatrao007
2 parents e822159 + d9a7d3c commit a8891a3

3 files changed

Lines changed: 86 additions & 23 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Problem Statement:
3+
There are n people standing in a circle (n is even). Each person looks at the person
4+
standing exactly opposite them. Given that person a looks at person b, determine
5+
the person that person c is looking at.
6+
7+
---------------------------------------
8+
Approach:
9+
If 'a' looks at 'b', then the distance between a and b must be exactly n/2.
10+
Let dist = |a - b|. Then n = 2 * dist.
11+
Once n is known, the person opposite to c is:
12+
- c + dist, if it does not exceed n
13+
- otherwise, c - dist
14+
15+
If c is greater than n, then the configuration is invalid.
16+
17+
----------------------------------------
18+
19+
Time Complexity: O(1)
20+
21+
Space Complexity: O(1)
22+
23+
----------------------------------------
24+
Example:
25+
Input:
26+
a = 1, b = 3, c = 2
27+
28+
Process :
29+
1. Calculate dist = |1 - 3| = 2
30+
2. Calculate n = 2 * dist = 4
31+
3. Since c = 2, calculate opposite:
32+
- c + dist = 2 + 2 = 4 (which is <= n)
33+
- So, the person opposite to c is 4.
34+
35+
Output:
36+
4
37+
38+
--------------------------------
39+
*/
40+
41+
#include <bits/stdc++.h>
42+
using namespace std;
43+
44+
int main() {
45+
int t;
46+
cin >> t;
47+
while (t--) {
48+
int a, b, c;
49+
cin >> a >> b >> c;
50+
51+
52+
int d = abs(a - b);
53+
int n = 2 * d;
54+
// 2*10^8 fits in int.
55+
56+
// Invalid configuration, Answer does not exist
57+
if (d == 0 || c > n) {
58+
cout << -1 << "\n";
59+
continue;
60+
}
61+
62+
int ans;
63+
if (c + d <= n)
64+
ans = c + d;
65+
else
66+
ans = c - d;
67+
68+
cout << ans << "\n";
69+
}
70+
return 0;
71+
}

contributers.md

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
| Name | GitHub ID | College Name |
2-
| ---------------------- | ----------------------- | --------------------------------------------------------- |
3-
| Pradip Maity | @codeboy-pro | Haldia Institute Of Technology |
4-
| Asra Tabassum | Tabassumasra05 | IIIT Allahabad |
5-
| Aaroh Parwekar | aaroh-dell | Bharati Vidyapeeth |
6-
| Suyash | Skr-suyash | IIIT Allahabad |
7-
| Mannat Jain | mannatjain11465-netizen | IIIT Allahabad |
8-
| Prashant Kumar Dwivedi | dwivediprashant | LNCT Bhopal |
9-
| Arnav Singh | arnavsingh010 | IIIT Allahabad |
10-
| Mohan Kumar | aricthecoder | IIIT Allahabad |
11-
| Vishva Modh | ViMo018 | IIIT Allahabad |
12-
| Varad Singhal | VaradSinghal | SRMIST |
13-
| Hardik Singh Rana | hardik-rana02 | IIIT Allahabad |
14-
| OMDEEP | omicoded19 | IIITA |
15-
| BEESA MANISH | MANISH-BEESA | MLRIT |
16-
| Himansh Arora | Humanshere | IIIT Allahabad |
17-
| Kushagra Raghuvanshi | Taskmaster-afk | IIIT Allahabad |
18-
| Kamakshi Gupta | 29kamakshigupta | IIIT Allahabad |
19-
| Pranshu Sethi | iampranshusethi | IIIT Allahabad |
20-
| Abhay Pratap Singh | d2-e2-v2 | IIIT Allahabad |
21-
| Saurav Gitte | SauravGitte | IIIT Allahabad |
22-
| Aditya Shirsatrao | adityashirsatrao007 | N. K. Orchid College Of Engineering & Technology, Solapur |
1+
| Name | GitHub ID | College Name |
2+
|---------------------|----------------------|-------------------------------------------------------------------|
3+
| Pradip Maity | @codeboy-pro | Haldia Institute Of Technology |
4+
| Asra Tabassum | Tabassumasra05 | IIIT Allahabad |
5+
| Suyash | Skr-suyash | IIIT Allahabad |
6+
| Arnav Singh | arnavsingh010 | IIIT Allahabad |
7+
| Vishva Modh | ViMo018 | IIIT Allahabad |
8+
| Chanderkant Jhorar | novus547 | IIIT Allahabad |
9+
| Aditya Shirsatrao | adityashirsatrao007 | N. K. Orchid College Of Engineering & Technology, Solapur |
2310

24-
<!-- ADD ABOVE THIS -->
11+
<!-- ADD ABOVE THIS -->
2512
<!-- example | Korvac | Betty | Reyansh College | -->

0 commit comments

Comments
 (0)