There is really only one "move" in the game. Alice needs to decide who should go first. After that, both players are playing mechanically.
To decide who goes first, Alice finds the least X such that no subset of the available numbers adds up to X. Play will end on turn X, and Alice wants to be the one whose turn that is. So, if X is odd, Alice plays first; otherwise she lets Bob play first.
To easily determine X, Alice uses a Sieve. You're probably familiar with the Sieve of Eratosthenes, used to find primes. Same idea, but with different rules for a different purpose.
Alice writes down the numbers from 0 to the sum of all the numbers on the table, and crosses off 0. Then she takes numbers from the table, one at a time, without replacement. When she takes off the number Y, she crosses off every number that is Y plus some previously-crossed off number. When she has done this for every number on the table, the smallest un-crossed-off number is X.
Notice that this works even if the numbers on the table are not all distinct.
It even works if some of them are negative or zero, except that then Alice's initial list runs from the sum of the negative numbers thru the sum of the positive numbers, and X is the least positive un-crossed-off number.
Improved solution
Assume the numbers on the table are distinct positive integers.
If there were no missing numbers, any sum up to $S(N) = N(N+1)/2$ could easily be gotten, and X would be $S(N) = 1$.
But there are missing numbers. Let's start with an empty table, add numbers to it in increasing order, and after placing each number $n$ compute $S(n)$ = sum of all numbers on the table up to $n$. The question is, is it still true that a player could get any sum up to $S(n)$ from these numbers, assuming it was true for $S(n-1)$ before placing $n$.
Well, if $n \le S(n-1)+1$, then the answer is clearly yes. You could already get any sum up to $S(n-1)$ without using $n$. To get a sum $s$ where $S(n-1) \lt s \le S(n)$, combine $n$ with a combination summing to $s - n$ from the smaller numbers.
Conversely, if $n \gt S(n-1)+1$, then the answer is no. The sum $S(n-1)+1$ is unachievable without using $n$, because it exceeds the sum of the other numbers, and is also unachievable using $n$, because $n$ by itself is already too large.
And that leads to an obvious $O(N)$ algorithm to find X
X = 1
for n from 1 to N
break if n > X
X += n unless n is one of the missing numbers
end
return X
(I assume it's obvious how to do unless n is one of the missing numbers
in constant time, assuming they are given to us in ascending order.)
But if $K$ is much smaller than $N$ we can do better. Suppose we're given the missing numbers in ascending order. Then
MSUM = 0
for each missing number m
MSUM += m
X = m * (m + 1)/2 - MSUM + 1
return X if m >= X
end
return N * (N + 1)/2 - MSUM + 1
This runs in time $O(K)$.
No, that is not correct. The Pythagorean theorem applies only to right triangles. Here, the simplest way to do the problem is to use the "cosine rule". Move vector F2 to the tip of vector F1 and draw the line connecting the base of F1 to the tip of F2. That gives a triangle in which two sides have "length" 30 and 40. The angle between them, inside the triangle, is 180- 60= 120 degrees. By the "cosine law", if a triangle has two sides of length a and b, and the angle between them is C, then the length of the third side is given by $c^2= a^2+ b^2- 2ab cos(C)$ (In the case that C is a right triangle, cos(C)= 0 so that becomes the Pythagorean theorem. In the case that C is a straight angle (180 degrees), cos(C)= -1 so that becomes $c^2= a^2+ b^2+ 2ab= (a+ b)^2 or c= a+ b.).
Here, taking a= 30, b= 40, and C= 120 degrees, $c^2= 900+ 1600- 2400 (-1/2)= 900+ 1600+ 1200= 3700$ so $c= \sqrt{3700}= 10\sqrt{37}$.
(Paul, no. The direction of the two vectors is as given in the picture. "N here is "Newtons", not "North".)
Best Answer
Suppose there are $2n$ vectors.
Alice can avoid losing by using the following strategy . . .
Let $S$ be the sum of all $2n$ vectors.
On Alice's $i$-th turn, let Alice choose the vector, $a_i$ say, among the yet unchosen vectors such that the dot product $a_i\cdot S$ is largest, and let $b_i$ denote the vector chosen by Bob on his $i$-th turn.
Let $A=a_1+\cdots +a_n$ and let $B=b_1+\cdots +b_n$.
By choice of $a_i$, we have $a_i\cdot S\ge b_i\cdot S$.
It follows that $A\cdot S\ge B\cdot S$, hence $$ |A|^2-|B|^2 = A\cdot A-B\cdot B = (A-B)\cdot (A+B) = (A-B)\cdot S \ge 0 $$