Skip to content

Commit 9fc8cef

Browse files
authored
Add solution for circle problem in Solution1.cpp
Implement solution for finding person in circle based on given conditions.
1 parent fb643f5 commit 9fc8cef

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* 1 to n people are standing in a circle. n is even.... a is looking at b.
2+
If given c is looking at some d person for given a,b then find that d. If such a combination
3+
of circle does not exist then print -1*/
4+
5+
// Time complexity: O(1)
6+
// Space complexity: O(1)
7+
//My submission: https://codeforces.com/contest/1560/submission/355204246
8+
9+
#include <bits/stdc++.h>
10+
using namespace std;
11+
12+
using ll = long long;
13+
#define all(x) (x).begin(), (x).end()
14+
15+
const int MOD = 1e9 + 7; // 998244353
16+
const ll INF = 1e18;
17+
18+
void solve() {
19+
int a,b,c;
20+
cin>>a>>b>>c;
21+
int n=2*abs(a-b);
22+
if(a>n || b>n ||c>n ) cout<<-1<<endl;
23+
else{
24+
int x=c-n/2,y=c+n/2;
25+
if(x>=1 && x<=n) cout<<x<<endl;
26+
else cout<<y<<endl;
27+
}
28+
}
29+
30+
int main() {
31+
// Fast I/O
32+
ios::sync_with_stdio(false);
33+
cin.tie(nullptr);
34+
35+
int t;
36+
cin >> t;
37+
while (t--) {
38+
solve();
39+
}
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)