Skip to content

Commit 61faff2

Browse files
authored
Merge pull request #147 from DeadlySatwik/issue3
Issue3
2 parents 645ada0 + ff3f596 commit 61faff2

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: Solution1","url":"c:\\Project\\OpenCode25\\CP-Chronicles\\Problems\\Mathematics\\Day-01\\sol\\Satwik_Santosh\\Solution1.cpp","tests":[{"id":1766771594036,"input":"","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Project\\OpenCode25\\CP-Chronicles\\Problems\\Mathematics\\Day-01\\sol\\Satwik_Santosh\\Solution1.cpp","group":"local","local":true}
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+
1. Determine the circle size (n): Since 'a' and 'b' are opposite, the distance between them
10+
is half the circle. Thus, n = 2 * |a - b|.
11+
2. Validation: If any of the given numbers (a, b, c) aregreater than n, the configuration
12+
is impossible. Output -1.
13+
3. Find opposite of 'c': The person opposite to 'c' is at a distance of n/2 from 'c'.
14+
15+
----------------------------------------
16+
17+
Time Complexity: O(1)
18+
19+
Space Complexity: O(1)
20+
21+
----------------------------------------
22+
Example:
23+
Input:
24+
a = 1, b = 3, c = 2
25+
26+
Process :
27+
1. Calculate diff = |1 - 3| = 2
28+
2. Calculate n = 2 * diff = 4
29+
3. Since c = 2, calculate opposite:
30+
- c + diff = 2 + 2 = 4 (which is <= n)
31+
- So, the person opposite to c is 4.
32+
33+
Output:
34+
4
35+
*/
36+
37+
#include <bits/stdc++.h>
38+
using namespace std;
39+
#define ll long long
40+
#define out(x) cout << (x) << endl
41+
#define outr(x) \
42+
{ \
43+
cout << x << endl; \
44+
return; \
45+
}
46+
47+
void solve()
48+
{
49+
ll a, b, c;
50+
cin >> a >> b >> c;
51+
ll diff = abs(a - b);
52+
ll n = diff * 2;
53+
54+
if (a > n || b > n || c > n)
55+
{
56+
outr(-1);
57+
}
58+
ll ans = c + diff;
59+
if (ans > n)
60+
ans -= n;
61+
out(ans);
62+
}
63+
64+
int main()
65+
{
66+
ll t;
67+
cin >> t;
68+
while (t--)
69+
solve();
70+
return 0;
71+
}

Problems/Mathematics/Day-01/sol/Saurav_Gitte/Solution1.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ int main() {
6868
cout << ans << "\n";
6969
}
7070
return 0;
71-
}
71+
}
72+
73+
//Submission Link: https://codeforces.com/problemset/submission/1560/355215212

0 commit comments

Comments
 (0)