What is prefix and prefix product?
The prefix and, prefix product are also called prefixes and arrays, prefixed by the plot no group.
Give an array a,
Prefix and: Create a new array B, each item in the array B[i] Save the and of [0...i] in A;
Suffix and: Create a new array B, each item in the array B[i] Save the and of [i...n-1] in A;
Prefix Product: Creates a new array B, each item in the array B[i] saves the product of a [0...i];
Suffix product: Create a new array B, each item in the array B[i] Save the product of [i...n-1] in A;
Application of prefix and prefix product (example): 1, Topic 1:
Given a floating-point group A, an array of b,b[i]=a[0]*a[1]*...*a[i-1]*a[i+1]*...*a[n-1], you cannot use division and do not allow new open arrays.
Ideas:
Ask for "suffix product" first:
for (int i=n-1;i>=0;i-) b[i]=a[i]* ((i==n-1) 1:b[i+1]);
Incidentally, "prefix product":
for (int i=0,j=1;i<n;j*=a[i++]) b[i]=j* ((i==n-1) 1:b[i+1]);
2. Topic 2:
For successive periods in an array and the absolute value of the smallest?
Ideas:
Prefix and nature of: a[i]+a[i+1]+...+a[j]=sum[j]-sum[i-1]
Prefix and sort, take minimum
3. Topic 3:
Separates an array from the middle P position so that the difference between a[0]+...+a[p-1] and a[p]+a[p+1]+...+a[n-1] is minimized?
Ideas:
- Prefix and-(sum-prefix and) =2* prefix and-sum, are the minimum of the formula;
- If all are non-negative, you can take the "two sweep" method, and the smaller one more than a number;
(array) prefix and prefix product and its application