Skip to content

Commit 6738f4e

Browse files
authored
Merge pull request #264 from sahsudhanshu/main
Added Solution1.cpp
2 parents 86812f8 + fa99c43 commit 6738f4e

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
typedef long long ll;
3+
typedef long double ld;
4+
using namespace std;
5+
6+
/*
7+
Problem Statement:
8+
There are n people standing in a circle (n is even). Each person looks at the person
9+
standing exactly opposite them. Given that person a looks at person b, determine
10+
the person that person c is looking at.
11+
12+
Approach:
13+
- Determine the circle size n Since a and b are opp. the distance between them diameter
14+
- If any of the given numbers a, b and c are greater than n the configuration
15+
is impossible. Output -1.
16+
- Find opposite of c
17+
18+
Time Complexity: O(1)
19+
Space Complexity: O(1)
20+
*/
21+
22+
23+
int main()
24+
{
25+
ll t;
26+
cin >> t;
27+
while (t--)
28+
{
29+
ll a, b, c;
30+
cin >> a >> b >> c;
31+
32+
ll t = 2 * abs(a - b);
33+
34+
if (t >= a && t >= b && c <= t)
35+
{
36+
if (c > t / 2)
37+
cout << c - t / 2 << endl;
38+
else
39+
cout << t / 2 + c << endl;
40+
}
41+
else
42+
cout << -1 << endl;
43+
}
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)