Const N = 13; Var A,B:array[1..N] of integer; i:integer; S1,S2:real; Begin Randomize; S1:=0; S2:=0; Write('A('); For i:= 1 to N-1 do Begin A[i]:=random(201)-100; Write(A[i],',') End; A[N]:=random(201)-100; Write(A[N],')'); WriteLn;
Write('B('); For i:= 1 to N-1 do Begin B[i]:=random(201)-100; Write(B[i],',') End; B[N]:=random(201)-100; Write(B[N],')'); WriteLn; WriteLn; Write('|A| = '); For i:= 1 to N do Begin S1:=S1+A[i]*A[i]; End; S1:=Sqrt(S1); WriteLn(S1); Write('|B| = '); For i:= 1 to N do Begin S2:=S2+B[i]*B[i]; End; S2:=Sqrt(S2); WriteLn(S2); WriteLn; Write('Ближайшая точка: '); if S1 < S2 then WriteLn('A') else WriteLn('B') End.
Это и будет наименьшее время.
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int n,i,s;
bool priz=true;
cin>>n;
int b[n],c[n];
for (int i=0; i<n; i++)
{
cin>>b[i];
c[i]=i+1;
}
// сортировка масcива по не возрастанию
while (priz)
{
priz=false;
for (int i=0; i<n-1; i++)
{
if (b[i]<b[i+1])
{
swap(b[i],b[i+1]);
swap(c[i],c[i+1]);
priz=true;
}
}
}
s=0;
for (int i=0; i<n; i++) s+=b[i]*(i+1);
cout<<s<<endl;
for (int i=0; i<n; i++) cout<<c[i]<<" ";
cout<<endl;
system("pause");
return(0);
}
Ввод - вывод:
6
10 21 13 36 41 9
332
5 4 2 3 1 6
N = 13;
Var
A,B:array[1..N] of integer;
i:integer;
S1,S2:real;
Begin
Randomize;
S1:=0;
S2:=0;
Write('A(');
For i:= 1 to N-1 do
Begin
A[i]:=random(201)-100;
Write(A[i],',')
End;
A[N]:=random(201)-100;
Write(A[N],')');
WriteLn;
Write('B(');
For i:= 1 to N-1 do
Begin
B[i]:=random(201)-100;
Write(B[i],',')
End;
B[N]:=random(201)-100;
Write(B[N],')');
WriteLn;
WriteLn;
Write('|A| = ');
For i:= 1 to N do
Begin
S1:=S1+A[i]*A[i];
End;
S1:=Sqrt(S1);
WriteLn(S1);
Write('|B| = ');
For i:= 1 to N do
Begin
S2:=S2+B[i]*B[i];
End;
S2:=Sqrt(S2);
WriteLn(S2);
WriteLn;
Write('Ближайшая точка: ');
if S1 < S2 then WriteLn('A')
else WriteLn('B')
End.