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.
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; }
to the point explanation ... :-) nice
ReplyDeletethankx :)
Deletethanks :) n yeah nyc explanation :)
ReplyDeletei was making the larger one settle first .. :/
You're complicating this. The answer is just ceil(max(b, g)/(min(b, g) + 1))
ReplyDeleteSure, you might also find one more simpler formula. But its not about the formula, its about how you arrive at it, which I think the blog does.
Delete