Saturday, 18 July 2015

ATOMS

Atoms in the Lab

Link to the question : ATOMS 

HINT : 

At every second,a single atom breaks  into k atoms. Hence if there are n atoms at time t, then at time t+1 there will be n*k atoms. Since, there is a limit given to the maximum number of atoms m, we need to check if n*k is smaller than m and thereby also keep counting the time.

RECOMMENDED QUESTION :

Try this very simple question after getting an AC in this one.

SOURCE CODE : 

#include<stdio.h>
int main()
{
    int p;
    scanf("%d",&p);
    while(p--)
    {
        unsigned long long int n,k,m,s=1,t=0;
        scanf("%llu%llu%llu",&n,&k,&m);
        if(n>m)
            printf("0\n");
        else
        {
            while(s<=m/n)
            {
                s=s*k;
                if(s<=m/n)
                    t++;
            }
            printf("%llu\n",t);
        }
    }
    return 0;
}

Friday, 17 July 2015

ARRAYSUB

SUBARRAYS

Link to the question : ARRAYSUB 

HINT :

I have applied the basic approach and it got accepted.  First I started a loop from 0 to [size - k]. And then for sub sequence of k elements, I printed the maximum element. This is done by brute force.

RECOMMENDED QUESTION :

Try your hands on this mathematical question .

SOURCE CODE :

#include<iostream>

using namespace std;
int main()
{
    int n,k,i,j,m=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    cin>>k;
    for(i=0;i<=n-k;i++)
    {
        m=a[i];
        for(j=1;j<k;j++)
        {
            if(a[i+j]>m)
                m=a[i+j];
        }
        cout<<m<<" ";

    }
}

ARMY


Army Strength

Link to the question :  ARMY

HINT :

The question may sound a little tricky or  difficult but actually its very simple. If you read it carefully, you will notice that all you need to do is sort both the armies and compare the last element of both the armies and then predict the result.

RECOMMENDED QUESTION :

Try your hands on this mathematical question.

SOURCE CODE :

#include<iostream>

#include<algorithm>

using namespace std;



int main()

{

    int t,ng,nm,i;

    cin>>t;

    cout<<endl;

    while(t--)

    {

        cin>>ng>>nm;

        int g[ng],m[nm];

        for(i=0;i<ng;i++)

            cin>>g[i];

        for(i=0;i<nm;i++)

            cin>>m[i];

        sort(g,g+ng);

        sort(m,m+nm);

        

            if(g[ng-1]>=m[nm-1])

            

                cout<<"Godzilla"<<endl;

                

            else

                cout<<"MechaGodzilla"<<endl;

        }
return 0;

}


AP3

AP - Complete The Series v2

 Link to the question : AP3

HINT :

Again a simple question based on the arithmetic progression. The problem becomes tricky if not taken care of the precisions.

RECOMMENDED QUESTION :

Try your hands on this question .

SOURCE CODE :

#include<stdio.h>
#include<math.h>

int main()
{
    int t; scanf("%d",&t);
    while(t--)
    {
       long long int a3,a3l,s,i,a,d,len; 
          
      long double n,sq,diff;
      scanf("%lld",&a3);
      scanf("%lld",&a3l);
      scanf("%lld",&s);
     
      sq=sqrtl(((5.0*a3l+7.0*a3+2.0*s)*(5.0*a3l+7.0*a3+2.0*s))-(48.0*(a3l+a3)*s));
      n=((5.0*a3l+7.0*a3+2.0*s)+sq)/(2.0*(a3l+a3));
     
      len=llrintl(n);
      printf("%lld\n",len);
     
      diff=(a3l-a3)/(len-6.0);
      d=llrintl(diff);
     
      a=(a3-(2*d));
       for(i=0;i<len;i++)
       {
                       printf("%lld ",a+i*d);
       }
        printf("\n");
      
      
       }  
     
     return 0;
}

Wednesday, 15 July 2015

AP2


AP - Complete The Series (Easy)

Link to the question : AP2 

HINT : 

Simply apply the formulae that you have learnt in your elementary school. A very easy question on arithmetic progression , even the question states it. But dont forget to simplify the equations a bit if you dont want your code to be  a bit messy.

RECOMMENDED QUESTION :

Try this gcd question .

SOURCE CODE :

#include<stdio.h>
int main()
{
    int t;
    long long int sum, n3,l3,a,d,i,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld %lld %lld",&n3,&l3,&sum);
        n= (2*sum)/(n3+l3);
        d= (l3-n3)/(n-5);
        a= n3 - 2*d;
        printf("%lld\n",n);
        for(i=1;i<=n;i++)
            {
                printf("%lld ",a);
                a= a+d;
            }
            printf("\n");
    }
    return 0;
}

ANARC09B


Tiles of Tetris, Not!

Link to the question : ANARC09B 

HINT :

A very simple question. By looking at the example or by just getting the feel of the question you will understand that all you need to find is the least common multiple of the two numbers.

RECOMMENDED QUESTION :

Try this p&c question after this one.

SOLUTION :

 #include<iostream>

 using namespace std;

int main()

{



    long long  a=1,b=1,g;



    while(a!=0 && b!=0)

    {

        cin>>a>>b;

        if(a!=0 && b!=0) {

        long long i;

        while(a%2==0 && b%2==0)

        {

            a=a/2;

            b=b/2;

        }

        long long

         s;

        if(a<b)

            s=a;

        else s=b;

        for(i=3;i<=s;i=i+2)

        {

            while(a%i==0 && b%i==0)

            {

                a=a/i;

                b=b/i;

            }

        }

        cout<<a*b<<endl;

    } }

    return 0;



}



AMZSEQ


AMZ Word

Link to the question : AMZSEQ 

HINT : 

A very good question on dynamic programming. We take an array a[] and assign a[0] = 1. Now, we can make  1 letter words in 3 ways , i.e, use any of the digit. Similarly if you solve for 2 letter words by applying a bit of permutation and combination, you will get it to be 7. Similarly, by using the relation , a[2] = 7 , in 3 letter words, you will find number of ways to be 17. Hence we conlude the conclusion that a[i]= 2* a[i-1] + a[i-2]. 

RECOMMENDED QUESTION :

Try your hands on this simple question.

SOURCE CODE: 

#include <iostream>
using namespace std;
int main()
{
long long int a[25];
int  x;
a[0] = 1;
a[1] = 3;
for(int i = 2; i < 25; i++)
a[i] = 2*a[i-1] + a[i-2];
cin >> x;
cout << a[x] << endl;
return 0;
}

Sunday, 12 July 2015

AMZRCK

Amz Rock

Link to the question : AMZRCK 

HINT : 

A very nice problem of fibonacci numbers and dynamic programming. Dont know but I think can be done with minimal processing also.

SOURCE CODE :

#include <iostream>
using namespace std;
int main()
{
long long int a[45];
int t, x;
a[0] = 1;
a[1] = 2;
for(int i = 2; i < 45; i++)
a[i] = a[i-1] + a[i-2];
cin >> t;
for(int i = 0; i < t; i++)
{
cin >> x;
cout << a[x] << endl;
}
return 0;
}

AMR12D

The Mirror of Galadriel

Link to the question : AMR12D 

HINT :

If you go through th question and see the example, you will notice that all sub strings are palindrome only if the entire string is palindrome. So we just need to check  whether the input string is palindrome. 

SOURCE CODE :

#include<stdio.h>
#include<string.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char a[100],k,i;
        scanf("%s",a);
        k=strlen(a);
        int f=0;
        for(i=0;i<k/2;i++)
        {
            if(a[i]!=a[k-i-1])
            {
                f=1;
                break;
            }
        }
        if(f==0)
            printf("YES\n");
        else
            printf("NO\n");
    }


    return 0;
}

ALICESIE

Alice Sieve

Link to the question : ALICESIE 

HINT :

A very simple question. The algorithm is based on Hit and Trial approach. Just solve for a few odd numbers and some even numbers, you will get to know how it is done and what to do.

SOURCE CODE :

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