Created
October 28, 2014 10:20
-
-
Save Sd-Invol/c832fb7c9bf7fa665657 to your computer and use it in GitHub Desktop.
一看就懂的最近邻搜索
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void getNearest(int p , int k) { | |
| if (!p) return; | |
| if (t[p].vis) { | |
| LL dis = dist(P , t[p].u); | |
| if (dis < res || (dis == res && t[p].o < t[ret].o)) | |
| res = dis , ret = p; | |
| } | |
| if (k) { | |
| if (cmpY(P , t[p].u)) { | |
| getNearest(t[p].c[0] , k ^ 1); | |
| if (sqr(P.second - t[p].u.second) <= res) | |
| getNearest(t[p].c[1] , k ^ 1); | |
| } else { | |
| getNearest(t[p].c[1] , k ^ 1); | |
| if (sqr(P.second - t[p].u.second) <= res) | |
| getNearest(t[p].c[0] , k ^ 1); | |
| } | |
| } else { | |
| if (cmpX(P , t[p].u)) { | |
| getNearest(t[p].c[0] , k ^ 1); | |
| if (sqr(P.first - t[p].u.first) <= res) | |
| getNearest(t[p].c[1] , k ^ 1); | |
| } else { | |
| getNearest(t[p].c[1] , k ^ 1); | |
| if (sqr(P.first - t[p].u.first) <= res) | |
| getNearest(t[p].c[0] , k ^ 1); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment