Last active
March 7, 2020 00:09
-
-
Save JanhaviDadhania/4453bb2e3fee8d9a343f9b0461a80bef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chef has decided to take break from her busy schedule. She decides to visit Hogwarts. As chef is from moggle world she is | |
not aware that voldemort has poisoned the water bodies in hogwarts. There are two perfect circular water bodies inside forbidden forest | |
with negligible width. One of them is maintained by house gryffindor and other by house slytherin. Hagrid is good friend of | |
chef and has gifted her broomstick to travel around. | |
Broomstick has few characteristics as below: <br> | |
1. Hogwards has infinite area and broomstick can start from anywhere outside forbidden forest <br> | |
2. It always travel in straight line <br> | |
3. Once started, it will not stop and will continue to fly till infinity <br> | |
4. The path it follows must be tangent to the ring maintained by house Gryffendor <br> | |
5. Broomstick always fly at ground level <br> | |
Chef uses this broomstick to travel. The safe index of chef is given by the following formula. <br> <br> | |
safe index = 5 * (number of times chef's path touches nonpoisoned ring) + (-2) * (number of times chef's path touches | |
poisoned ring) <br> <br> | |
Help chef to maximise total safe index by choosing best possible path. <br> <hr> | |
Input <br> | |
First line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. | |
First and second line of every test case contains three space separated integers x y r and one char c. | |
First line has information about ring maintained by Gryffindor and second line has information about ring maintained by | |
slytherin. | |
where x,y are x and y coordinates of center of the ring and r is radius of the ring. | |
If last character is p, it indicates that the ring is poisoned. | |
If last character is n, it indicates that the ring is not-poisoned. <br> <hr> | |
Output <br> | |
For each test case print the single line containing maximum possible safe index of chef. <br> <hr> | |
Constraints <br> | |
0 <= t <= 100 <br> | |
0 <= x,y <= 10^18 <br> | |
1 <= r <= 10^18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
#define loop(n) for(int i=0;i<n;i++) | |
#define ll long long | |
using namespace std; | |
double find_distance(ll a, ll b, ll c, ll d) { | |
double one = abs(a-c); | |
double two = abs(b-d); | |
double mid_distance = sqrt((one * one) + (two * two)); | |
return mid_distance; | |
} | |
int main() { | |
int t; | |
cin>>t; | |
loop(t) { | |
ll g_x, g_y, g_r; | |
ll s_x, s_y, s_r; | |
char g_p, s_p; | |
cin>>g_x>>g_y>>g_r>>g_p; | |
cin>>s_x>>s_y>>s_r>>s_p; | |
double distance; | |
distance = find_distance(g_x,g_y,s_x,s_y); | |
//cout<<distance; | |
ll result; | |
if(distance == 0 ) { | |
if( g_r == s_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2) + (-2); | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = 5 - 2; | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5 - 2; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5; | |
} | |
} | |
else if( g_r > s_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = -2; | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = -2; | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5; | |
} | |
} | |
else if( g_r < s_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2) + (-2) + (-2); | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = (-2) + 5 + 5; | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5 + (-2) + (-2); | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5 + 5; | |
} | |
} | |
} | |
else if( distance >= (g_r+g_r) ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2); | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = 5 + 5 + (-2); | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5 + 5; | |
} | |
} | |
else if(distance < (g_r+g_r) ) { | |
if( g_r <= s_r ) { | |
if( g_r + distance == s_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2) + (-2) ; | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = 5 + 5 + (-2); | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5 - 2; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5 + 5; | |
} | |
} | |
else if( g_r + distance > s_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = -2 ; | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = 5 + 5 + (-2); | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5 + 5; | |
} | |
} | |
else if( g_r + distance < s_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2) + (-2) + (-2) ; | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = 5 + 5 + (-2); | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5 - 2 - 2 ; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5 + 5; | |
} | |
} | |
} | |
else if( g_r > s_r ) { | |
if ( s_r + distance == g_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2); | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = 5 + (-2); | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5 ; | |
} | |
} | |
else if( s_r + distance < g_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2); | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = (-2); | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5; | |
} | |
} | |
else if( s_r + distance > g_r ) { | |
if( g_p == 'p' && s_p == 'p' ) { | |
result = (-2); | |
} | |
else if( g_p == 'p' && s_p == 'n' ) { | |
result = (-2) + 5 + 5 ; | |
} | |
else if( g_p == 'n' && s_p == 'p' ) { | |
result = 5; | |
} | |
else if( g_p == 'n' && s_p == 'n' ) { | |
result = 5 + 5 + 5; | |
} | |
} | |
} | |
} | |
cout<<result<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment