Skip to content

Commit 60f2f01

Browse files
Merge pull request #86 from verifiedHuman18/solution1
Add solution 1
2 parents ed01599 + 51dd262 commit 60f2f01

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

852 Bytes
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// CODEFORCES SUBMISSION LINK: https://codeforces.com/contest/1560/submission/355168755
2+
3+
/*
4+
PROBLEM STATEMENT :
5+
6+
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).
7+
8+
Each person is looking at the person standing exactly opposite him in the circle.
9+
10+
You are given three distinct integers a, b, and c. It is known that person a is looking at person b.
11+
12+
Determine the number of the person that person c is looking at.
13+
If there are multiple answers, print any of them.
14+
If there is no answer, print -1.
15+
*/
16+
17+
/*
18+
Approach:
19+
We first calculate the size of the circle. Knowing 'a' and 'b' is enough to know the size of the circle.
20+
Because we can know the number of people between 'a' and 'b' which would give us half the total number.
21+
We can easily get the person sitting opposite to any number once we know the size of the circle.
22+
*/
23+
24+
/*
25+
Time Complexity: O(1)
26+
Space Complexity: O(1)
27+
*/
28+
29+
import java.util.Scanner;
30+
31+
public class Solution1 {
32+
public static void main(String[] args) {
33+
Scanner sc = new Scanner(System.in);
34+
int t = sc.nextInt();
35+
while (t-- > 0) {
36+
int a = sc.nextInt();
37+
int b = sc.nextInt();
38+
int c = sc.nextInt();
39+
int d;
40+
41+
int n = 2 * Math.abs(a - b);
42+
if (a > n || b > n || c > n)
43+
d = -1;
44+
else {
45+
int res = (c + (n / 2)) % n;
46+
d = res != 0? res : n;
47+
}
48+
49+
System.out.println(d);
50+
}
51+
sc.close();
52+
}
53+
}

0 commit comments

Comments
 (0)