morris821028 / UVa

:love_letter: UVa and other online judege workspace
556 stars 268 forks source link

UVa 11236 Grocery store - Why check to result again? #28

Closed morris821028 closed 7 years ago

morris821028 commented 7 years ago

Content

想請問您這題
https://github.com/morris821028/UVa/blob/master/volume112/11236%20-%20Grocery%20store.cpp

為什麼要加上
if(fabs((a+b+c+d)/100.0 - ((double)a*b*c*d)/100000000.0) < 1e-12)

我以為 d 是直接用整數運算 d = (s * 1000000) / (p - 1000000); 算出來所以應該是對的
而且 if(s > 2000 || d < c)   continue; 檢查過 d 的範圍了應該直接是答案了

為什麼要重新檢查一次呢?

我不加那行結果 WA 了 QQ

謝謝您
morris821028 commented 7 years ago

Because of the integer division, variable d maybe not a correct solution.

In fact, we just check whether (s * 1000000) is a multiple of (p - 1000000) easily. Finally, using it to instead of full re-check is faster than old version.

It is fixed in commit https://github.com/morris821028/UVa/commit/7463e2ad548313a6ef4f7ada00e3dc4d07d85734 .