ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1371. Cargo Agency

Precision question
Posted by Samsonov Alex [USU] 16 Sep 2005 17:09
What precision should we use in output?

Could I have WA#17 because of it?

Is double (long double) enough for us?
Re: Precision question
Posted by Vladimir Yakovlev (USU) 16 Sep 2005 21:44
with a precision of 4 decimal digits.

double is always enough for calculatings on Timus.
Re: Precision question
Posted by Samsonov Alex [USU] 16 Sep 2005 23:09
Then it (4 digits) should be written in russian statement.
Fixed. (-)
Posted by Vladimir Yakovlev (USU) 17 Sep 2005 00:29
Re: Precision question
Posted by Igor Dex 7 Oct 2005 01:32
To avoid precision problems it is possible to use only integer numbers in solving this task, but I have the same WA#17.
Re: Precision question
Posted by Burunduk1 7 Oct 2005 23:54
Do you use int64? Check it.
(50 000 * 50 000 = 2 500 000 000)
Re: Precision question
Posted by Igor Dex 8 Oct 2005 02:06
Yes, of cause, I use unsigned __int64.
Re: Precision question
Posted by Samsonov Alex [USU] 9 Oct 2005 18:27
I tried double, __in64 and long double and still WA17. That must be some other bug...
Re: Precision question
Posted by Antonov Yuri (USU) 10 Oct 2005 00:02
Maybe problem with the following code:

for ( i = 1; i <= m_N; ++i )
for ( j = 1; j <= m_N; ++j )
sum += t[ i ][ j ];

sum /= N * (N - 1);

It must be obviously changed to ...
for ( i = 1; i <= m_N; ++i )
for ( j = 1; j <= m_N; ++j )
sum += t[ i ][ j ]) / ( N * (N - 1));

overflow ...

Maybe it will be usefull :- )
Re: Precision question
Posted by Samsonov Alex [USU] 10 Oct 2005 21:58
And again I've tried both variants... Still WA17
Re: Precision question
Posted by Antonov Yuri (USU) 10 Oct 2005 22:44
Why both variants! First fragment implyies WA ( it`s obvious )
Did you convert N to __int64 ? It was noted that N*N > signed int.

Hmmm ... Send me your code ( see e-mail in my profile )
Re: Precision question
Posted by Samsonov Alex [USU] 23 Oct 2005 21:59
Yes. The bug what in these data types. I think I should love __int64 from this task and further. Thank you very much! I got AC.
Re: Precision question
Posted by Denis Koshman 19 Aug 2008 03:56
I used __int64 (signed) to get total sum of all paths. Then I casted it to double before division by n*(n-1)/2. Got WA41. That happened because 'n' was 'int' and that multiplication overflowed. Then I casted 'n' to 'int64' inside that multiplication and got AC.