qingyuge006's blog

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.

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

»
5 years ago, # |
  Vote: I like it -21 Vote: I do not like it

Auto comment: topic has been updated by qingyuge006 (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

B not C

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

What's clever in that?