File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Sudhanshu Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments