Sunday, 26 July 2015

GIRLSNBS

Standard

Girls and Boys

Link to the question : GIRLSNBS 

HINT :

Let g be the number of girls and b be the number of boys and let b>g. Now, if * represents the girls and let their arrangement be like :
      *     *      *      *        *   , then think how many boys will you fill on those spaces so that you get the minimum gender regularity.There are g+1 spaces. So first we fit all the spaces with equal number of boys and then distribute the remaining boys to one boy per space.

RECOMMENDED QUESTION :

I would like my readers to solve this question after trying this one.

SOURCE  CODE :

#include<stdio.h>

int main()

{

    int g,b,x=1,y=1;

    while(x!= -1 && y!=-1)

    {

                scanf("%d%d",&g,&b);

                x=g; y=b;

                if(x!=-1 && y!=-1)

                {

                    if(g==b){

                            if(g==0)

                               printf("0\n");

                       else

                        printf("1\n");

                    }

                    else

                    {

                        if(g>b)

                        {

                            x=g; y=b;

                        }

                        else{ x=b; y=g;}

                        if((x%(y+1))==0)

                            printf("%d\n",(x/(y+1)));



                        else

                            printf("%d\n",(x/(y+1))+1);

                    }

                }

    }

    return 0;

}
    

3 comments:

  1. to the point explanation ... :-) nice

    ReplyDelete
  2. thanks :) n yeah nyc explanation :)
    i was making the larger one settle first .. :/

    ReplyDelete