J
jiashenglv
Unregistered / Unconfirmed
GUEST, unregistred user!
条件是若a1>=0,则b1=a1;a1<0,则a1和随后的数a[2..k]相加,直到其和(sum[1,2..k])>=0之后则其和为b1;依此类推。如:
case 1、a={8,2,4,9,0,12,24},则b={8,2,4,9,0,12,24};
case 2、a={8,-2,-4,9,0,-12,24},则b={8,3,0,12};
//8>0,b1=8;-2+(-4)+9=3>0,b2=3;b3=0;b4=(-12+24)=12;
case 3、a={8,-2,-4,9,0,-12,-24},则b={8,3,0,-36};
//若按题目条件最后全部的数之和sum[i..m]<0,则b[last]=sum[i..m];
//8>0,b1=8;-2+(-4)+9=3>0,b2=3;b3=0;b4=(-12+(-24))=-36<0,但是数列已到结尾,b4=-36;
case 4、a={8,-2,-4,9,0,12,-24},则b={8,3,0,12,-24};
//8>0,b1=8;-2+(-4)+9=3>0,b2=3;b3=0;b4=12;b5=-24;
请给出算法和源程序。在线等待
case 1、a={8,2,4,9,0,12,24},则b={8,2,4,9,0,12,24};
case 2、a={8,-2,-4,9,0,-12,24},则b={8,3,0,12};
//8>0,b1=8;-2+(-4)+9=3>0,b2=3;b3=0;b4=(-12+24)=12;
case 3、a={8,-2,-4,9,0,-12,-24},则b={8,3,0,-36};
//若按题目条件最后全部的数之和sum[i..m]<0,则b[last]=sum[i..m];
//8>0,b1=8;-2+(-4)+9=3>0,b2=3;b3=0;b4=(-12+(-24))=-36<0,但是数列已到结尾,b4=-36;
case 4、a={8,-2,-4,9,0,12,-24},则b={8,3,0,12,-24};
//8>0,b1=8;-2+(-4)+9=3>0,b2=3;b3=0;b4=12;b5=-24;
请给出算法和源程序。在线等待