Skip to content

Commit d7d5723

Browse files
committed
UPDATED File strcutre
1 parent 9900d19 commit d7d5723

4 files changed

Lines changed: 130 additions & 23 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define ll long long
5+
#define pb push_back
6+
#define f(i,a,b) for (ll i = a; i < b; i++)
7+
#define fb(i,a,b) for (ll i = a; i >= b; i--)
8+
#define all(v) (v).begin(), (v).end()
9+
10+
typedef vector<int> vi;
11+
typedef vector<ll> vl;
12+
typedef pair<int,int> pii;
13+
typedef pair<ll,ll> pll;
14+
15+
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
16+
17+
ll binexp(ll a, ll b) {
18+
ll res = 1;
19+
while (b > 0) {
20+
if (b & 1) res = res * a;
21+
a = a * a;
22+
b >>= 1;
23+
}
24+
return res;
25+
}
26+
27+
void solve() {
28+
int a,b,c;
29+
cin>>a>>b>>c;
30+
if(c>2*abs(a-b) or a>2*abs(a-b) or b>2*(abs(a-b))){
31+
cout<<-1<<endl;
32+
}
33+
else{
34+
if(c>abs(a-b)) cout<<c-abs(a-b)<<endl;
35+
else cout<<c+abs(a-b)<<endl;
36+
}
37+
}
38+
39+
int main() {
40+
fastio;
41+
int t = 1;
42+
cin >> t;
43+
while (t--) solve();
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Problem Statement:
3+
There are n people standing in a circle (n is even). Each person looks at the person
4+
standing exactly opposite them. Given that person a looks at person b, determine
5+
the person that person c is looking at.
6+
7+
---------------------------------------
8+
Approach:
9+
If 'a' looks at 'b', then the distance between a and b must be exactly n/2.
10+
Let dist = |a - b|. Then n = 2 * dist.
11+
Once n is known, the person opposite to c is:
12+
- c + dist, if it does not exceed n
13+
- otherwise, c - dist
14+
15+
If c is greater than n, then the configuration is invalid.
16+
17+
----------------------------------------
18+
19+
Time Complexity: O(1)
20+
21+
Space Complexity: O(1)
22+
23+
----------------------------------------
24+
Example:
25+
Input:
26+
a = 1, b = 3, c = 2
27+
28+
Process :
29+
1. Calculate dist = |1 - 3| = 2
30+
2. Calculate n = 2 * dist = 4
31+
3. Since c = 2, calculate opposite:
32+
- c + dist = 2 + 2 = 4 (which is <= n)
33+
- So, the person opposite to c is 4.
34+
35+
Output:
36+
4
37+
38+
--------------------------------
39+
*/
40+
41+
#include <bits/stdc++.h>
42+
using namespace std;
43+
44+
int main() {
45+
int t;
46+
cin >> t;
47+
while (t--) {
48+
int a, b, c;
49+
cin >> a >> b >> c;
50+
51+
52+
int d = abs(a - b);
53+
int n = 2 * d;
54+
// 2*10^8 fits in int.
55+
56+
// Invalid configuration, Answer does not exist
57+
if (d == 0 || c > n) {
58+
cout << -1 << "\n";
59+
continue;
60+
}
61+
62+
int ans;
63+
if (c + d <= n)
64+
ans = c + d;
65+
else
66+
ans = c - d;
67+
68+
cout << ans << "\n";
69+
}
70+
return 0;
71+
}

contributers.md

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1+
| Name | GitHub ID | College Name |
2+
|---------------------|----------------------|-------------------------------------------------------------------|
3+
| Pradip Maity | @codeboy-pro | Haldia Institute Of Technology |
4+
| Asra Tabassum | Tabassumasra05 | IIIT Allahabad |
5+
| Suyash | Skr-suyash | IIIT Allahabad |
6+
| Arnav Singh | arnavsingh010 | IIIT Allahabad |
7+
| Vishva Modh | ViMo018 | IIIT Allahabad |
8+
| Chanderkant Jhorar | novus547 | IIIT Allahabad |
9+
| Aditya Shirsatrao | adityashirsatrao007 | N. K. Orchid College Of Engineering & Technology, Solapur |
110

2-
| Name | GitHub ID | College Name |
3-
|-------------------------|------------------------|---------------------------------|
4-
| Pradip Maity | @codeboy-pro | Haldia Institute Of Technology |
5-
| Asra Tabassum | Tabassumasra05 | IIIT Allahabad |
6-
| Aaroh Parwekar | aaroh-dell | Bharati Vidyapeeth |
7-
| Suyash | Skr-suyash | IIIT Allahabad |
8-
| Mannat Jain | mannatjain11465-netizen| IIIT Allahabad |
9-
| Prashant Kumar Dwivedi | dwivediprashant | LNCT Bhopal |
10-
| Arnav Singh | arnavsingh010 | IIIT Allahabad |
11-
| Mohan Kumar | aricthecoder | IIIT Allahabad |
12-
| Vishva Modh | ViMo018 | IIIT Allahabad |
13-
| Varad Singhal | VaradSinghal | SRMIST |
14-
| Hardik Singh Rana | hardik-rana02 | IIIT Allahabad |
15-
| OMDEEP | omicoded19 | IIITA |
16-
| BEESA MANISH | MANISH-BEESA | MLRIT |
17-
| Himansh Arora | Humanshere | IIIT Allahabad |
18-
| Kushagra Raghuvanshi | Taskmaster-afk | IIIT Allahabad |
19-
| Kamakshi Gupta | 29kamakshigupta | IIIT Allahabad |
20-
| Pranshu Sethi | iampranshusethi | IIIT Allahabad |
21-
| Abhay Pratap Singh | d2-e2-v2 | IIIT Allahabad |
22-
| Saurav Gitte | SauravGitte | IIIT Allahabad |
23-
<!-- ADD ABOVE THIS -->
11+
<!-- ADD ABOVE THIS -->
2412
<!-- example | Korvac | Betty | Reyansh College | -->
25-

0 commit comments

Comments
 (0)