Showing posts with label pen-paper. Show all posts
Showing posts with label pen-paper. Show all posts

Saturday, 5 September 2015

MKEQUAL

Make them equal !

Link to the question : MKEQUAL 

HINTS :

Very simple problem. Pen paper work. Try out with any n numbers such tha sum of n numbers is not divisible ny n and again with n numbers such that this time its divisible. You will definitely get the logic.

SOURCE CODE :


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n],i;
        long long int s=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            s=s+a[i];
        }
        if(s%n==0)
            cout<<n<<endl;
        else
            cout<<n-1<<endl;

    }

    return 0;
}

Thursday, 6 August 2015

IITKWPCB

Check the coprimeness

Link to the question : IITKWPCB 

HINT :

Observe the test cases and derive the formula.

SOURCE CODE :

#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
    long long int n,c;
    scanf("%lld",&n);
    if(n%2==0)
    {
        c=n/2 - 1;
        if(c%2==0)
            printf("%lld\n",c-1);
        else
            printf("%lld\n",c);
    }
    else
    {
        printf("%lld\n",n/2);
    }
}
return 0;
}
 

Wednesday, 29 July 2015

HC


Happy Coins

Link to the question : HC

HINT :

You can ignore the word consecutive. Though I wont say it misleading, but not taking that into consideration will make the problem solving a bit more simple. Try some cases and even if you cant check the source code.

SOURCE CODE :


#include<stdio.h>

#include<string.h>

int main()

{

long int t,i,n,count=0;

char s[4],a[]="lxh";

scanf("%ld",&t);

while(t--)

{

    count=0;

    scanf("%ld",&n);

    while(n--)

    {

        scanf("%s",s);

        if(strcmp(s,a)==0)

            count++;

    }

    if(count%2==0)

        printf("hhb\n");

    else

        printf("lxh\n");



}

return 0;



}

RECOMMENDED QUESTION :

After solving this question, I would like you to try your hands out in this question . 

Thursday, 23 July 2015

EIGHTS


Triple Fat Ladies

Link to the question : EIGHTS 

HINT :

No need to hard code. Just take out your calculator and check for the first few numbers whose cube ends with 888 and observe the pattern. 

Still cant get the pattern?
Here it is : 
1 - 192
2 - 442
3 - 692
4 - 942

RECOMMENDED  QUESTION :

Try solving this question.

SOURCE CODE :

#include<iostream>


using namespace std;

int main()

{

    long long k,t;

    cin>>t;

    while(t--)

    {

        cin>>k;

        cout<<192 + (k-1)*250<<endl;





    }

    return 0;

}

Wednesday, 22 July 2015

DANGER


In Danger

Link to the question : DANGER 

HINT :

Josephus problem can be solved by using a circular queue but for k=2 we can derive a formula. First try solving by keeping number of people, n, equal to some power of 2, i.e, 4,8 etc. You will notice that the last to stay is at position 1. 
Hence we write  n = 2^m + t. Now, if t people are killed, the one with whom the cycle starts stays till the end. So, after killing t people, the cycle will start from the position 2*t - 1. Hence, you need to find that position.

RECOMMENDED QUESTION :

After getting an AC, try solving this question .

SOURCE CODE :

/* In Danger */

/* Sushant Gupta */



#include<stdio.h>

#include<math.h>

int main()

{

    char a[10];

    scanf("%s",a);



    while(1)

    {

        if(a[0]== '0' && a[1]== '0')

            return 0;



        long long int x;

        x = 10 * (a[0] - '0') + (a[1]- '0');

        x = x * pow(10, (a[3]- '0'));

        int m;

        m = log2(x);

        long long int n;

        n = pow(2,m);

        long long int ans;

        ans = 2*(x - n) + 1;

        printf("%lld\n",ans);

        scanf("%s",a);

    }



}

Tuesday, 21 July 2015

CRDS



Cards

Link to the question : CRDS 

HINT :

A very simple question. Just observe the pattern and derive a formula.

RECOMMENDED QUESTION :

Try this adhoc question .

SOURCE CODE :

#include<iostream>

using namespace std;

int main()

{

    long long t,n,s;

    cin>>t;



    while(t--)

    {

        cin>>n;

        s= (2*n*(n+1)/2) + (n*(n-1)/2);

        cout<<s%1000007<<endl;

    }



    return 0;

}

Saturday, 18 July 2015

BEENUMS


Beehive Numbers

Link to the question : BEENUMS 

HINT :

The question may be a bit lengthy and also it might be difficult for us to imagine a beehive following the norms as per the question. But we dont have to worry about that. All we need to observe is the pattern in given example and VOILA our question is solved. 


RECOMMENDED QUESTION :

Try your hands in this question.

SOURCE CODE :

#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,x=1,y;
    double t;
    while(x!=-1)
    {
        scanf("%lld",&n);
        x=n;
        if(x!=-1)
        {
            if(n%6==1)
            {
                  t= sqrt(1+ (4*(n-1)/3));
                  y= (int)(t*10);
                  if(y==t*10)
                    printf("Y\n");
                  else
                    printf("N\n");
            }
            else
            printf("N\n");
        }
    }
    return 0;
}