qingyuge006's blog

By qingyuge006, history, 5 years ago, In English

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!

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By qingyuge006, 5 years ago, In English

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.

Full text and comments »

  • Vote: I like it
  • -26
  • Vote: I do not like it