i am trying to solve this problem of spoj spoj.com/problems/DAB/1 . I know that this a conditional probability question. But i am still getting WA. The code is

#include<stdio.h>
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int t, n, k;
    char sweet;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        int l[n], g[n], r[n];
        double sum = 0., prob;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d%d", &l[i], &g[i], &r[i]);
//            printf("l = %d g = %d r = %d\n", l[i], g[i], r[i]);
        }
        scanf("%d", &k);
        getchar();
        scanf("%c", &sweet);
//        getchar();
//        printf("sweet = %d\n", sweet);
        if(sweet == 'L')
        {
            double temp = (double)l[k-1] / (l[k-1] + g[k-1] + r[k-1]);
            for(int i=0; i<n; i++)
                sum += ((double)l[i] / (l[i] + g[i] + r[i]));
            prob = temp / sum;
            cout << setprecision(9) << prob << endl;
//            printf("%.10lf\n", prob);
        }
        else if(sweet == 'G')
        {
            double temp = (double)g[k-1] / (l[k-1] + g[k-1] + r[k-1]);
            for(int i=0; i<n; i++)
                sum += ((double)g[i] / (l[i] + g[i] + r[i]));
            prob = temp / sum;
            cout << setprecision(9) << prob << endl;
//            printf("%.10lf\n", prob);
        }
        else
        {
            double temp = (double)r[k-1] / (l[k-1] + g[k-1] + r[k-1]);
            for(int i=0; i<n; i++)
                sum += ((double)r[i] / (l[i] + g[i] + r[i]));
            prob = temp / sum;
            cout << setprecision(9) << prob << endl;
//            printf("%.10lf\n", prob);
        }
    }
    return 0;
}

please check if there is some error...

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 17 10d

Want to read more? Browse other topics in C and C++ or view latest topics.