Wednesday 1 July 2015

KURUK14

GENIE SEQUENCE

Link to the question: KURUK14 

HINT :

If you do some for rough work for some inputs with n > 4, you will notice that in order for an array, a[ ],  to be a genie sequence, a[i] should be < n and also all the numbers should either be equal to index, i, or 
n - 1 - i. So we create an array an array and initialize its element with 0. Then we take the element of the array in a variable c and check for the conditions. 
If a[c] = 0 then make it 1 else make a[n-c-1] = 1.

SOURCE CODE:

/* Genie Sequence - (KURUK 14) */
/* Sushant Gupta */

#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,i,f=0,c;
        scanf("%d",&n);
        int a[n];
        for(i=0;i<n;i++)
            a[i]= 0;
        for(i=0;i<n;i++)
        {
             scanf("%d",&c);
             if(c<n)
             {
                 if(a[c]==0)
                    a[c]=1;
                 else
                    a[n-1-c]=1;
             }

        }
        for(i=0;i<n;i++)
        {
            if(a[i]==0)
                f=1;
        }
        if(f==0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
  

2 comments:

  1. hey can you please tell me that how to come a (n-c-1).
    i saw your code but i didn't get. so can you please me.

    ReplyDelete
    Replies
    1. I have updated the explaination. I hope it helps.

      Delete