Because there is the same amount of water in each sample, the samples have an equal amount of influence over the overall temperature. that means it will be somewhere right in the middle of the two original temperatures. The middle, also the average, of the two samples' temperatures is 30c, meaning that if you combined the 20c water and the 40c water the final result would be 100g of 30c water. If you need some more explanation, just ask.
The final temperature of mixing 50g of water at 20°C and 50g at 40°C is 30°C. This is calculated as the average of the two initial temperatures. The principle used here is based on thermal equilibrium.
;