http://mirror.codeforces.com/contest/1196/submission/60503250 Got wrong answer
q = int(input())
for i in range(q):
piles = [int(i) for i in input().split()]
piles.sort()
print(piles[1] + int((piles[2] - (piles[1] - piles[0])) / 2))
http://mirror.codeforces.com/contest/1196/submission/60503474 Got accepted
q = int(input())
for i in range(q):
piles = [int(i) for i in input().split()]
piles.sort()
print(piles[1] + ((piles[2] - (piles[1] - piles[0])) // 2))
In my opinion, they do the same work but results are not the same. There is a difference between // operator and int() probably. I searched it but could not find anything. Does anyone know it?
when you use "/2" it becomes a float type and your wrong answer is because of the floating representation of numbers in python
5/2 =2.5
5//2 == 2
For more — https://www.tutorialspoint.com/python3/python_basic_operators.htm
As many have already pointed out, in Python 3
a/b
is the floating point division, anda//b
is the floored division. However note that in Python 2 botha/b
anda//b
are floored divisions when a and b are integers. To make Python 2 behave like Python 3, start the source code withfrom __future__ import division
. I usually just stick to using//
in both Python 2 and 3 when I want floored division.