Description
Input
Input multiple sets of test cases, a line test in each group, four integers x1, y1, x2, y2, have the meaning described in the subject. EOF input file to the end.
Output
Sample Input
3 0 1 2
6 0 4 0
Sample Output
5
0
Data Constraint
Competitions
One game lacks ideas, mainly feeling cold, poor mental condition.
FIG painting, blind ** guess a magical conclusion:
when the slope of the two vectors are the same, the answer is 0.
When two vectors are not the same, the answer is to choose one of the shortest.
Feeling nothing issue, then go Sike two questions behind the cancer.
Game coming to an end, the conclusion seems suddenly found something wrong?
/ <_
answer
We look at the top where my conclusion was wrong -
see the two angles equal to 120 °, equal to the length of the vector.
Then add two vectors is equal to the vector length.
If this angle between the larger point, is less than the vector length is long.
So, this type of situation we want to do a good job!
Direct Conclusion No. 1 - the angle between two vectors when an angle greater than 60 °, to the use of my conclusions.
Otherwise, see No. 2 conclusion, then mess things to do.
No. 1 proved conclusion:
I direct interception of proof on paper, or a good push (to start a paper saying that was wrong, that number should be equal to or greater)
Then we take a look at 2 conclusions:
\ (| + by AX | = | A (X-\ the y-the lambda) + (b + A \ the lambda) the y-| \) , ie the vector \ ((x, y) \ ) can be converted into \ ((X-\ the lambda Y, Y) \) , and the coefficients \ ((a, b) \ ) can be converted into coefficients \ ((a, b + a
\ lambda) \) demonstrated clearly.
Because this thing is their own free coefficient determined.
So, using the above vector can be turned into something new vector, while expanding angle.
Thus in the process of constantly expanding, the angle will eventually be greater than 60 °, back to a conclusion.
Then we look at the specific ways to expand:
or chart paper
we set \ (\ overrightarrow {OE} \ ) as \ (\ overrightarrow {OB} \ ) in \ (\ overrightarrow {OA} \ ) projected on.
So then there are three cases:
. 1, \ (| \ OA overrightarrow {} | <| \ overrightarrow the OE {} | \)
In this case, the above figure is, regardless of conversion.
Set \ (\ overrightarrow {OC} = \ lambda * \ overrightarrow {OA} \) and in which \ (\ the lambda \) is satisfied \ (| \ overrightarrow {OC} | <| \ overrightarrow {OE} | \) of the case of \ (\ lambda \) maximum.
So now you can convert it.
Obviously, \ (\ angle {} the DCB> \ angle the AOB} {\)
so we'll \ ((\ overrightarrow {CB} , \ overrightarrow {OA}) \) is substituted, recursively.
2, \ (| \ OA overrightarrow {} |> | \ OE overrightarrow {} | \)
that is similar to the above \ (\ overrightarrow {OD} \
) we find, \ (\ angle ADB {}> \ angle { } the AOB \) , then the proof according to D E axisymmetric folded over, is found outside corner.
The \ ((\ overrightarrow {DB} , \ overrightarrow {OA}) \) substituting recursively!
3, \ (| \ OA overrightarrow {} | = | \ OE overrightarrow {} | \)
In fact, this situation can note, written not be possible to correctly infinite loop.
It is roughly like this, is not like gcd algorithm process? This is called class Euclidean algorithm.
Some small details:
- How to quickly find \ (\ lambda \) it?
\ (\ lambda = \ lfloor \ frac {| \ overrightarrow {OE} |} {| \ overrightarrow {OA} |} \ rfloor \) - When the recursion is greater than the angle 90 °, should as a rotational vector 180 °.
- Time Complexity: Because above this, it is proved that the time complexity becomes extremely complicated. (In fact, I was too Cai a)
Standard process
uses math;
type
nod=record
x,y:extended;
end;
var
i,j,k,l,n,m,anss:longint;
co,kk:extended;
a,b,c:nod;
function jia(a,b:nod):nod;
begin
jia.x:=a.x+b.x;
jia.y:=a.y+b.y;
end;
function jian(a,b:nod):nod;
begin
jian.x:=a.x-b.x;
jian.y:=a.y-b.y;
end;
function cheng(lid:extended;a:nod):nod;
begin
cheng.x:=lid*a.x;
cheng.y:=lid*a.y;
end;
function cross(a,b:nod):extended;
begin
exit(a.x*b.x+a.y*b.y);
end;
function dis(a:nod):extended;
begin
exit(sqrt(a.x*a.x+a.y*a.y));
end;
function ans(a:nod):extended;
begin
exit(a.x*a.x+a.y*a.y);
end;
function likegcd(a,b:nod):extended;
var
c:nod;
det,k:extended;
begin
if (dis(a)>dis(b)) then
begin
c:=a;a:=b;b:=c;
end;
if (dis(a)=0) then
begin
exit(0);
end;
if (dis(b)=0) then
begin
exit(0);
end;
co:=cross(a,b)/(dis(a)*dis(b));
if (co<0) then
begin
a.x:=-a.x;
a.y:=-a.y;
exit(likegcd(a,b));
end;
if (co=1) then
begin
exit(0);
end;
c.x:=b.x*co;
c.y:=b.y*co;
kk:=pi;
if (co<=1/2) then
begin
if (dis(a)>dis(b)) then exit(ans(b))
else exit(ans(a));
end;
if (dis(a)>dis(c)) then
begin
exit(likegcd(jian(b,a),a));
end
else
begin
k:=trunc(dis(c)/dis(a));
exit(likegcd(jian(b,cheng(k,a)),a));
end;
end;
begin
assign(input,'math.in');reset(input);
assign(output,'math.out');rewrite(output);
while not eof do
begin
readln(a.x,a.y,b.x,b.y);
c.x:=-a.x;
c.y:=-a.y;
if dis(jia(c,b))>dis(jia(a,b)) then a:=c;
anss:=trunc(likegcd(a,b));
writeln(anss);
if anss=5584 then
i:=i;
end;
end.