File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Ayush_Saha Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ PROBLEM STATEMENT :
3+
4+ 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).
5+
6+ Each person is looking at the person standing exactly opposite him in the circle.
7+
8+ You are given three distinct integers a, b, and c. It is known that person a is looking at person b.
9+
10+ Determine the number of the person that person c is looking at.
11+ If there are multiple answers, print any of them.
12+ If there is no answer, print -1.
13+ */
14+
15+ /*
16+ Approach:
17+ We first calculate the size of the circle. Knowing 'a' and 'b' is enough to know the size of the circle.
18+ Because we can know the number of people between 'a' and 'b' which would give us half the total number.
19+ We can easily get the person sitting opposite to any number once we know the size of the circle.
20+ */
21+
22+ import java .util .Scanner ;
23+
24+ public class Solution1 {
25+ public static void main (String [] args ) {
26+ Scanner sc = new Scanner (System .in );
27+ int t = sc .nextInt ();
28+ while (t -- > 0 ) {
29+ int a = sc .nextInt ();
30+ int b = sc .nextInt ();
31+ int c = sc .nextInt ();
32+ int d ;
33+
34+ int n = 2 * Math .abs (a - b );
35+ if (a > n || b > n || c > n )
36+ d = -1 ;
37+ else {
38+ int res = (c + (n / 2 )) % n ;
39+ d = res != 0 ? res : n ;
40+ }
41+
42+ System .out .println (d );
43+ }
44+ sc .close ();
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments