Showing posts with label probability. Show all posts
Showing posts with label probability. Show all posts

Wednesday, 29 July 2015

HEADSHOT

Headshot

Link to the question : HEADSHOT 

HINT :

The question requires a bit of your probability skills. Use the greedy approach. And if still not able to derive the formula, try to grasp it up with the source code.

SOURCE CODE :

/* Headshot */
/* Sushant Gupta */
#include<stdio.h>
#include<string.h>
int main()
{
    char a[150];
    int i,n,w=0,b=0;
    float rot,sht;
    scanf("%s",a);
    n = strlen(a);
    for(i=0;i<n;i++)
    {
        if(a[i]=='0')
            w++;


    }
    rot = (float)w/n;
    for(i=0;i<n-1;i++)
    {
        if(a[i]=='0' && a[i+1]=='0')
            b++;
    }
    if(a[0]=='0' && a[n-1]=='0')
        b++;
    sht = (float)b/w;

    if(rot == sht)
        printf("EQUAL\n");
    else if(rot>sht)
        printf("ROTATE\n");
    else
        printf("SHOOT\n");
    return 0;
}

Saturday, 25 July 2015

FUNPROB

Yanu in Movie theatre

Link to the question : FUNPROB 

RECOMMENDED QUESTION :

Try solving this question after solving this.

SOURCE CODE :

#include<stdio.h>
int main()
{
     int m=1,n=1;
     double x,y;
     while(m!=0 && n!=0)
     {
         scanf("%d%d",&n,&m);
         if(n!=0 && m!=0)
         {
             if(n>m || m==0)
                printf("0.000000\n");
             else if(n==0)
                printf("1.000000\n");
             else
             {
                 x=m;
                 y=n;
                 printf("%.6lf\n",(x-y+1.0)/(x+1.0));
             }

         }
     }
     return 0;
}

Friday, 24 July 2015

FAVDICE


Favorite Dice

Link to the question : FAVDICE 

HINT :

Read some articels on : Expected value. Understand it properly and then implement the formula.

SOURCE CODE :

#include<stdio.h>

int main()
{
    int t,n,i;
    float s;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        s=0;
        for(i=1;i<=n;i++)
            s= s+ (float)1/(i);
        s=(float)(s*n);
        printf("%.2f\n",s);
    }



    return 0;
}



RECOMMENDED QUESTION :

I would like my reader to solve this question after this one.