sachin.magdum
BAN USERAmit's logic can be generalized, for R,G,B... and so on. by using Array of place pointer.
In the above example and Bi and Ri are used as place pointers, same way. We are using two pointer because we know we have two type of objects.
Later on if number of R,G,B... are numerious, then searchin in array will require hashing.
for (int i=0; i<n; i++)
{
hash[arr[i]] ++;
}
Can you please type complete question?
- sachin.magdum July 22, 2010Why cant union in C++ have virtual functions -
1. virtual functions used with inheritance. unions do not take part in inheritance.
2. all the members of union shares same memory slot. physically base and derived members of derived class object are stored in separate memory locations. union says all my members will share same memory, inhetance says derived members will be stored after base class members hence unions can not take part in inheritance.
jbong's method is better for space complexity. We can improve speed by moving declaration of tmp out of for loop.
mast's - type casting from char to int will it not create temporary variables in memory?
After reading question again - it seems that we have identify if 9th ball is heavy or lighter that others.
It is possible in 2 weings only.
1. Divide balls in 3 groups A = 4, B =4, C =1
2. Compare A and B if same go to step 3. else go to step 4.
3. Compare any ball from A or B with ball in C. if ball in C is heavy then 9th ball is heavy else lighter. stop.
4. Choose the group which is heavy lets say A is heavy, divide A in to two groups A1=2 and A2=2.
5. if A1 == A2 means all balls is group A are even. and ball in group B is of less weight. else 9th ball is heavy as A was heavier than B. stop
Further, if we have to really identify defective ball we have divide 9 balls into A=3, B=3 and C=3 and this method is already explained above.
According to Gautam -
2 * sqrt { r*r + (r/2)*(r/2) }
= 2 * sqrt { r*r + r*r / 4 }
= 2 * sqrt { r*r *( 5 /4 ) }
= 2 * r * sqrt (5/4)
= r * sqrt (5)
~ r * 2.2360679774997896964091736687313
Accroding to Mandar -
r *(1 + sqrt (2))
~ r * 2.4142135623730950488016887242097
So mandar's way of calculating along surface digonal is not shortest. He should calculate from vertex to mid of any of the adjusant edge of the opposite vertex of that surface and then from there to the oppsite vertex.
for simplicity take a thread and simple cube and try how that thread want's to travel when you tie it from one vertex to another, it will stay on any side of the cube but will sleep down to the mid of the edge.
1. probality of picking 'white ball' from 'black container' is 1/5 and 'black ball' is 4/5.
2. 'white container' contains 3 existing 'white balls' + 1/5 new 'white balls'
and 4/5 new 'black balls'.
3. probabilty of the ball could be white is (3 + 1/5)/ (3+ 1/5 + 4/5)
= (16/5)/(4)
= 4/5
Repbrandysolsen, Area Sales Manager at AMD
I am a Social butterflies who enjoy travel.Have fun doing this job and project an atmosphere that reflects Amazon ...
They might be testing your patience level, who konws. And this kind of situation can always possible in any organization, we must be ready for it.
- sachin.magdum July 22, 2010