How to solve this problem?
Given n points in a plane and q queries in each query a point P is given, and for each query we have to find the minimum of the dot product of point P taken with the given n points.
1 <= n,q <= 10^5
0 <= |x|,|y| <= 10^9
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
How to solve this problem?
Given n points in a plane and q queries in each query a point P is given, and for each query we have to find the minimum of the dot product of point P taken with the given n points.
1 <= n,q <= 10^5
0 <= |x|,|y| <= 10^9
Название |
---|
It can be solved with convex hull trick. For a fixed point, try to rearrange the formula to make it work.
It looks to me like a 3D convex hull. How do you rearrange it?
First of all, we find lower convex envelope. Then we can run ternary search. It's the simplest way to do it. For max you would find upper convex envelope instead. If constraints would allow coordinates to be negative you would split points by their x(<0 and >=0) and do two queries.
Try problem squad from function cup 2019 it uses this concept but is a bit harder.
X1*x2+y1*y2=sqrt(x1^2+y1^2)*sqrt(x2^2+y2^2)*cos(a)
a is angle between vectors (x1, y1) and (x2, y2). |(x1,y1)|*|(x2,y2)| * cos(a) = (projectio)^2
This can be done with convex hull of dots and some binary search(lower hull for P.y>0 and upper hull for P.y<0)
P.s sorry for my poor english
I know a trendy question on this concept. ;)
It’s surprising how little the word “trendy” describes itself.