-
1. If you use this ** completely, it is problematic, and there is less input from n.
The sentence scanf("%d",&n);
2. If it is not the error of your copy, the reason for the timeout is that the algorithm you use to calculate the maximum and minimum values is not good, and what you complete inside the function body is a sorting process, in fact, the output of the maximum and minimum values at the same time can be achieved in 3n 2-2 time without sorting, and using a simpler algorithm.
3. If you pursue efficiency, using vector may be slower, and this kind of problem can completely eliminate such complex data structures.
Fill in the method of solving the maximum and minimum value problem in 3n 2-2 time.
First of all, compare the two pairs, and divide the n numbers into two groups, the large group and the small group.
of another group. (n/2)
The large group is divided into two groups by comparing them in pairs, and each group is divided into two groups.
n/2/2)
Recursively find the maximum value for a large set (tmax(n)=tmax(n2)+n2).
tmax(n)=n-1
Similar calculations are performed for small groups.
So t(n)=n 2+tmax(n 2)+tmin(n 2)=3n 2-2
-
What is the time complexity of your algorithm? However, neither ** nor the algorithm looks too good.
If the time complexity requirements are not too high, directly use a sort sort, and the first and last elements of the output are the minimum and maximum values, ** is also relatively simple, and the time complexity is o(nlogn), as follows:
#include
#include
#include
using namespace std;
int main()
int n,i;
cin>>n;
vectorvi(n);
for(i=0;i
#include
using namespace std;
int main()
int n,i;
cin>>n;
vectorvi(n);
for(i=0;imax) max=vi[i];
if(vi[i]printf("%d%d",min,max);
return 0;
-
(a-c)(b-c)
a·b-a·c-b·c+c^2
a·c-b·c+1
c·(a+b)+1
Since a and b are perpendicular, and a and b are both unit vectors, a+b = root number 2·a original -c· (Root No. 2a) 1
Root number 2a|·|c|·cosα+1
Root number 2cos +1
The root number 2+1 where is the angle between the vector root number 2a and the vector -c.
That is, when all three vectors are moved to the origin, a and b are at a 90° angle, and when c is in the same direction as the vector a+b, there is a minimum value - the root number is 2+1
-
A and C are collinear, and the friends are set to a k(2,1) (2k,k).
b+a=(2k-3,k+1),|b+a|2 (2k-3) 2+(k+1) 2 5k 2 10k 10 Buddy Spike 5(k-1) 2 5 5, so the report |b+a|The minimum value is 5
-
The vector abc is a unit vector, then c 2 = 1, a + b) 2 = a 2 + b 2+, so |a+b|= 2, so |a-c|.|b-c|
ab-(a+b).c+c^2
(a+b).c+1
|a+b|.|c|+1
-
a-c)(b-c)=ab-c(a+b)+c^2=0-c(a+b)+1ab=0∴a⊥b∴|a+b|= Root Trumpet Limb 2
So c(a+b)=|c||a+b|cos = 1 * root pre-macro 2 * cos root number 2 original 1 - root number 2
So the most repentant value is 1-2
-
a-c) (calendar zen b-c) = ab-c (a+b) + c 2 = 1-c(a+b) yinwei a*b=0 |a+b|= root number 2
a-c)(b-c)=1-1*root:2*1
1 - Root staring horn limb dust 2
-
a-c)(b-c)=ab-ac-bc+c*c, because the meme is c*c=1 ab=0 so.
a-c)(b-c)=-c(a+b)
And because a*b=0, Sodanxiang is digging in b with a perpendicular to b, a+b=root number 2, so that c is perpendicular to the vector (a+b), so the minimum of -c(a+b) is 0, and the minimum of the original formula is 1
-
Solution: From a*b=丨a丨丨b丨cos =2, we get cos =1 2, so = 2
You may wish to set a=(2,0), b=(1, 3), c=(x,y), (a-c)*(b-2c)=0, and substitute it to get 2x 2-5x+2+2y 2- 3y=0
can be reduced to (x-5 4) 2+(y- 3 2) 2=3 4, that is, the end point of c falls on the circle, then the minimum value of 丨b-c丨 is the minimum value of the distance from the point (1, 3) to the circle, that is, the distance from the point to the center of the circle minus the radius, and ( 7- 3) 2
-
m=(a-b)*(b-c)=a*b-b*b-a*c+b*c=-|b|²-a*c+b*c
1-c*(a-b)
Cause|a|=|b|=|c|=1, then |a-b|= 2, then: c*(a b)=|a-b|×|c|cosw= 2cosw, the maximum value is 2, then:
The minimum value of m is 1 2
-
∵|a|=|b|=|c|=1 ab=0 bb=1 (a-b)(b-c)=ab-ac-bb+bc=(b-a)c-1= 2cos -1 (set to be the angle between (b-a) and c).
The minimum cos is -1 (the angle is 180 at this point), and the minimum is -2-1 for a-b)(b-c).
Summary. Solution: For the derivative of CTAAB, it can be solved using the derivative of calculus. >>>More
Let's talk about the difference between foreach and for, foreach is traversal for objects, and there is no need to define the number of loops, but there is a disadvantage, foreach traversal takes read-only data, and cannot add, delete and modify objects in foreach, while for loops can. >>>More
#include
using namespace std; >>>More
If you define r as int, enter 10000 and that will automatically force the type conversion when multiplied. >>>More
int max(float fx,float fy)float fz;
fz=fx>fy?fx:fy; >>>More