Dot Product Optimization
Difference between en5 and en6, changed 14 character(s)
I have been trying to solve this problem on SPOJ--  (http://www.spoj.com/problems/DPMAX/) <br/>↵
After 6hrs of trying and 16 wrong submissions, I have finally decided to seek some help. <br/>↵
**Brief Overview**<br/>↵
We are given n vectors. The problem asks us to calculate the maximum dot product of every vector with any other vector including itself. The absolute value of x and y coordinates is less than equal to 10^5. And there are 2*10^5 vectors to process.<br/>  ↵
**My approach**<br/>↵
1.Take these vectors as points. Find their convex hull.<br/>↵
2. The answer for all vectors will be the dot product with another vector with its end as a point of convex hull found  <br/>↵
3.Hypothesis--The maximum dot product for a vector lying in first quadrant should be with a vector which forms the upper right hull of the convex hull, similarly for a second quadrant 
vector it should be with a vector which forms the upper righleft hull and so on.<br/>↵
4.So vectors in the four different quadrants are separated into 4 different groups and the vectors are sorted to be in anti-clockwise order for each group.<br/>↵
5.Indices of Right-most, top-most, bottom-most, left-most points of hull are found.<br/>↵
6. Two-pointer approach is applied with one pointer being the starting of the sorted group and the other being points on the hull.(left-most,bottom-most...)↵
Pairing will be of the form--First quadrant vectors with right-most point, Second quadrant vectors with the top most point and so on.<br/>↵
7.For the vector in consideration we move to the next point in counter-clockwise direction only if the dot-product of the next point with the vector is greater than the dot-product with current point, otherwise we move to the next vector.<br/>↵

This approach worked for this problem-[Biathlon 2.0](http://codeforces.com/problemset/gymProblem/100886/H)↵

My solution-- (http://codeforces.com/gym/100886/submission/28148901)↵
However the vectors were only lying in first-quadrant for this question.↵

I have generated lot of random test cases and checked with brute-force solution and it had no diff at all.<br/>↵
Here is my solution--(http://www.spoj.com/status/ns=19708915) <br/>↵

It would be great if you could tell me if my approach is wrong or some test case where my solution fails. <br/>  ↵
Thanks a lot for helping

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English ujzwt4it 2017-06-30 18:59:59 32
en6 English ujzwt4it 2017-06-30 18:50:22 14
en5 English ujzwt4it 2017-06-30 18:47:57 24
en4 English ujzwt4it 2017-06-30 18:41:48 34
en3 English ujzwt4it 2017-06-30 18:40:50 11
en2 English ujzwt4it 2017-06-30 18:40:19 47
en1 English ujzwt4it 2017-06-30 18:37:20 2244 Initial revision (published)