Skip to content

Commit 0daaeb9

Browse files
Added Solution1.cpp for Day-01 from Harjas
1 parent 9abe56a commit 0daaeb9

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Problem Statement:
3+
Given three distinct integers a, b, and c placed on a circle of even size,
4+
numbered clockwise from 1. Person a is opposite to person b.
5+
Find the number opposite to c. If no such circle exists, return -1.
6+
7+
Prefix Sums:
8+
Not applicable since the problem is purely mathematical and does not involve
9+
range queries or cumulative sums.
10+
11+
Time Complexity: O(1)
12+
Space Complexity: O(1)
13+
14+
Submission Link:
15+
https://codeforces.com/contest/1560/submission/355443029
16+
*/
17+
#include <bits/stdc++.h>
18+
using namespace std;
19+
20+
int main(){
21+
22+
int t;
23+
cin>>t;
24+
while(t--){
25+
int a,b,c,n;
26+
cin>>a>>b>>c;
27+
if(a>b) swap(a,b); //naming the bigger number b and smaller one a
28+
29+
int SizeOfCircle= 2*(b-a); // thinking: b and a form the diameter of circle
30+
31+
if(SizeOfCircle==2) cout<<-1<<endl; //edge case when a and b are adjacent
32+
else{
33+
if(c>SizeOfCircle|| b>SizeOfCircle) cout<<-1<<endl; // edge case when either c or the bigger number do not reside in the size
34+
else{
35+
int ans=0;
36+
if(c>b) ans=(c-(b-a)); // because a and b form diameter then c lies in upper or lower half and opposite of c also lies based on that
37+
else if(c<=b) ans=(c+(b-a));
38+
39+
if(ans<=0) ans+=SizeOfCircle;
40+
else if(ans>SizeOfCircle) ans-=SizeOfCircle; // fixing ans if it resides outside elements of circle
41+
42+
cout<< ans<<endl;
43+
}
44+
45+
46+
}
47+
}
48+
return 0;
49+
}

0 commit comments

Comments
 (0)