-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdab_sweets.cpp
73 lines (57 loc) · 1.07 KB
/
dab_sweets.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
long double probability(vector<long double> &v, int s_no ) {
return ( v[s_no] / (v[0] + v[1] + v[2]) );
}
long double bayes(vector<vector<long double> > &v, int n, char sweet ) {
int s_no;
if (sweet == 'L')
{
s_no = 0;
} else if (sweet == 'G')
{
s_no = 1;
}
if (sweet == 'R')
{
s_no = 2;
}
long double p1 = probability(v[n - 1], s_no);
long double p_total = 0;
for (int i = 0; i < v.size(); ++i)
{
p_total += probability(v[i], s_no);
}
return (p1/ p_total);
}
int main(int argc, char const *argv[])
{
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
vector<vector<long double> > v;
int k;
cin >> k;
for (int i = 0; i < k; ++i){
vector<long double> s;
long double l;
long double g;
long double r;
cin >> l;
cin >> g;
cin >> r;
s.push_back(l);
s.push_back(g);
s.push_back(r);
v.push_back(s);
}
long double n;
cin >> n;
char sweet;
cin >> sweet;
printf("%.9LF\n", bayes(v, n, sweet));
}
return 0;
}