Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define MAX 50005
- using namespace std;
- int n;
- double h[MAX];
- struct point {
- int x, y;
- bool operator<(const point &pt2) const {
- return x < pt2.x;
- }
- };
- point pontos[MAX];
- double dist(point a, point b) {
- return sqrt(pow(a.x - b.x, 2) + pow(a.y-b.y, 2));
- }
- bool compara(point a, point b) {
- return a.x < b.x;
- }
- map<point, int> indice;
- int main() {
- scanf("%d", &n);
- for (int i = 1; i <= n; i++) scanf("%d %d", &pontos[i].x, &pontos[i].y);
- for (int i = 1; i <= n; i++) indice[pontos[i]] = i-1;
- sort(pontos+1, pontos+n+1, compara);
- h[2] = dist(pontos[1], pontos[2]);
- vector<point> ateagora;
- ateagora.push_back(pontos[1]);
- ateagora.push_back(pontos[2]);
- point ansa = pontos[1], ansb = pontos[2];
- double ansc=h[2];
- for (int i = 3; i <= n; i++) {
- point pp; pp.x = pontos[i].x - h[i-1];
- h[i] = h[i-1];
- vector<point>::iterator it = lower_bound(ateagora.begin(), ateagora.end(), pp, compara);
- for (; it != ateagora.end(); it++) {
- point ponto = *it;
- if (dist(ponto, pontos[i]) < h[i]) {
- ansc = h[i] = dist(ponto, pontos[i]);
- ansa = ponto;
- ansb = pontos[i];
- }
- }
- ateagora.push_back(pontos[i]);
- }
- int a = min(indice[ansa], indice[ansb]), b = max(indice[ansa], indice[ansb]);
- printf("%d %d %.6f\n", a, b, ansc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement