Title:
The input data contains three lines,
The first line is an integer N, N<=100 represents the dimension of vector,
The second line is a non-negative integer N, the elements in the v1 is given, and each integer in the range of 32-bit integer, separated by a space,
The second line is a non-negative integer N, v2 is given, the elements of each integer in the range of 32-bit integer, separated by a space,
Requirements:
Output an integer, represented by rearranging the vector components, can obtain the minimum inner product value, the data to ensure the final results in the range of 32-bit integer,
Example:
Input:
5
1, 2, 3, 4, 5
1 0 0 1
Output:
6
my idea is to use two bubble sort the array a sort from big to small, a smallest, finally to multiply accumulation, but the output has been not to
Below is I write:
# include
using namespace std;
Int small (int a [], int [] b, int N)
{
Int sum=0;
int i,j;
For (I=0; I & lt; N; I++)
{
For (j=I; J & lt; N - I - 1; J++)
{
If (a [j] {
Int temp1=a, [j].
A [j]=a, a + 1 bonus to [j].
A [j + 1)=temp1;
}
}
}
For (I=0; I & lt; N; I++)
{
For (j=I; J & lt; N - I - 1; J++)
{
If (b [j] & gt; B [m + 1])
{
Int temp2=b [j];
B=b [j] [j=1];
B=[m + 1] temp2;
}
}
}
For (I=0; I & lt; N; I++)
The sum +=([I] a [I] * b);
return sum;
}
Int main ()
{
Int sum=0;
Int N=5;
Int a []={1, 2, 3, 4, 5};
,0,1,0,1 int [] b={1};
Sum=small (a, b, N);
Cout & lt;system("pause");
}
CodePudding user response:
B=b [j] [j=1];CodePudding user response:
Reference:# include
using namespace std;
Int small (int a [], int [] b, int N)
{
Int sum=0;
int i,j;
For (I=0; I & lt; N; I++)
{
For (j=0; J & lt; N - I - 1; J++)//for (j=I; J & lt; N - I - 1; J++)
{
If (a [j] {
Int temp1=a, [j].
A [j]=a, a + 1 bonus to [j].
A [j + 1)=temp1;
}
}
}
For (I=0; I & lt; N; I++)
{
For (j=0; J & lt; N - I - 1; J++)//for (j=I; J & lt; N - I - 1; J++)
{
If (b [j] & gt; B [m + 1])
{
Int temp2=b [j];
B=b [j] [j + 1);/[j]=b/b [j=1];
B=[m + 1] temp2;
}
}
}
For (I=0; I & lt; N; I++)
The sum +=([I] a [I] * b);
return sum;
}
Int main ()
{
Int sum=0;
Int N=5;
Int a []={1, 2, 3, 4, 5};
,0,1,0,1 int [] b={1};
Sum=small (a, b, N);
Cout & lt;system("pause");
}
CodePudding user response: