Блог пользователя qingyuge006

Автор qingyuge006, история, 5 лет назад, По-английски

Why do I get the "division by zero" error in this? https://codeforces.com/contest/1183/submission/56306470 I will be more than appreciated if you help me!

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор qingyuge006, 5 лет назад, По-английски

Algorithm: reverse all the positives; if(product is negative) reverse the smallest one.

Proof:
With step1, we got the ABS of the product the greatest.
After step 1, we got the product:
1)positive: No step2. We are done.
2)negative: suppose the product after step 1 is (-1000)*(-2)*k(k<0) .Either we choose (-1000)*1*k, or 999*(-2)*k;
In general, a*(a+b)*k(b,k<0). 1st choice:(-a-1)*(a+b)*k; 2st choice a*(-a-b-1)*k. To make a comparision:((-a^2-a-ab-b)-(-a^2-ab-a))*k=-b*k<0, so we choose to reverse the smallest one.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -26
  • Проголосовать: не нравится