Showing posts with label formula. Show all posts
Showing posts with label formula. Show all posts

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.

Saturday, 18 July 2015

BINSTIRL

Binary Stirling Numbers

Link to the question : BINSTIRL 

HINT :

Read the article on wikipedia on binary stirling numbers. There you will also find a formula  to check the pairity of them.

RECOMMENDED QUESTION :

Try this dp question .

SOURCE CODE :

#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
    long long int n,m;
scanf("%lld%lldd", &n, &m);
printf("%d\n", !((n-m)&((m-1)>>1)));
}
return 0;
}