Skip to content

Commit bd58766

Browse files
Merge pull request #167 from KushagraSahu-01/main
adding Solution to first problem
2 parents 53a7042 + 6553744 commit bd58766

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*PROBLEM STATEMENT :
2+
There are n people standing in a circle. They are numbered from 1 to n in a clockwise order. The circle is even (i.e. n is even).
3+
4+
Each person is looking at the person standing exactly opposite him in the circle.
5+
6+
You are given three distinct integers a, b, and c. It is known that person a is looking at person b.
7+
8+
Determine the number of the person that person c is looking at.
9+
If there are multiple answers, print any of them.
10+
If there is no answer, print -1.
11+
12+
Approach : the length of the circle will be |a-b|*2 so if any of a,b,c is greater than this we print -1 if this is not true we print c+|a-b| if it exists in the circle otherwise we print c-|a-b|
13+
Time Complexity : O(1)
14+
Space Complexity : O(1)
15+
Input
16+
7
17+
6 2 4
18+
2 3 1
19+
2 4 10
20+
5 3 4
21+
1 3 2
22+
2 5 4
23+
4 3 2
24+
Output
25+
8
26+
-1
27+
-1
28+
-1
29+
4
30+
1
31+
-1
32+
https://codeforces.com/problemset/submission/1560/355227237
33+
*/
34+
#include <iostream>
35+
using namespace std;
36+
int main() {
37+
int t;
38+
cin >>t;
39+
while(t--)
40+
{
41+
int a,b,c;
42+
cin >>a >>b>>c;
43+
int len=abs(a-b)*2;
44+
if(c>len||a>len||b>len)
45+
cout <<-1<<"\n";
46+
else
47+
{
48+
if(c+len/2<=len)
49+
cout <<c+len/2<<"\n";
50+
else
51+
cout << c-len/2<<"\n";
52+
}
53+
54+
}
55+
}

0 commit comments

Comments
 (0)