# THREDICE - Editorial

Tester & Editorialist: Aman Dwivedi

Cakewalk

Basic Maths

# PROBLEM:

There are three people, and each of them has an unbiased 6-sided die. The result of rolling a die will be a number between 1 and 6 (inclusive) with equal probability.

The three people throw their dice simultaneously. In this game, the third person wins only if his number is strictly greater than the sum of the other two numbers. Given that the first person rolls the value X and the second person rolls the value Y, what is the probability the third person will win?

# EXPLANATION:

The third player will win the game if and only if his number is greater than the sum of the other two numbers. Let us try to find his chances of winning the game:

As the third person has an unbiased 6-sided die, the number of possible outcomes is 6. Now let’s try to find out the favorable outcomes:

Say S denotes the sum of the value of X and Y. Now for winning, the third person should get the number greater than S in his die.

Case 1: S \ge 6

• In this case, the number of favorable outcomes for the third person is 0 as the dice don’t contain the number greater than 6.

Case 2: S<6

• In this case, the third person will win if we score greater than S. He can score anything between the range [S+1, S+2,\dots,6]. Hence the number of favorable outcomes in this case are:
fav = 6-S

Now as we know the number of favorable outcomes as well as the possible outcomes, we can easily find out the probability as:

probability = \frac{favorable}{possible}

Finally, we will output this probability.

# TIME COMPLEXITY:

O(1) per test case

# SOLUTIONS:

Setter
#include<bits/stdc++.h>
using namespace std;

void solve(int tc) {
int a, b; cin >> a >> b;
cout << fixed << setprecision(10) << (long double)(max(0, 6 - a - b)) / 6 << '\n';
}

signed main() {
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) solve(i);
return 0;
}

Tester
#include<bits/stdc++.h>
using namespace std;

#define int long long

long long readInt(long long l,long long r,char endd){
long long x=0;
int cnt=0;
int fi=-1;
bool is_neg=false;
while(true){
char g=getchar();
if(g=='-'){
assert(fi==-1);
is_neg=true;
continue;
}
if('0'<=g && g<='9'){
x*=10;
x+=g-'0';
if(cnt==0){
fi=g-'0';
}
cnt++;
assert(fi!=0 || cnt==1);
assert(fi!=0 || is_neg==false);

assert(!(cnt>19 || ( cnt==19 && fi>1) ));
} else if(g==endd){
if(is_neg){
x= -x;
}
assert(l<=x && x<=r);
return x;
} else {
assert(false);
}
}
}
string ret="";
int cnt=0;
while(true){
char g=getchar();
assert(g!=-1);
if(g==endd){
break;
}
cnt++;
ret+=g;
}
assert(l<=cnt && cnt<=r);
return ret;
}
long long readIntSp(long long l,long long r){
}
long long readIntLn(long long l,long long r){
}
}
}

void solve()
{
int x,y;

int sum = x+y;

if(sum>=6)
cout<<0<<"\n";
else
{
double num=(double)(6-sum);

double ans=num/6;

cout<<fixed<<setprecision(6)<<ans<<"\n";
}
}

int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);

// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);

int t;