URAL 2067

来源:互联网 发布:蔡文静演过的网络剧 编辑:程序博客网 时间:2024/05/17 01:46

题目大意是给定几个孩子的s值和r值,两个孩子之间的友情值是(sqrt((si - sj)^2 + (ri - rj)^2)) 1 <= i <= n && 1 <= j <= n

三个孩子的友情值是每两个孩子的友情值的总和再除以2,最好的朋友是对于任意两人u, v的友情值都有p(u, v) >= p(u, v, w)

w是第三个人


思路

构造

从友情值的计算可以看出两个孩子的友情值是平面坐标系上亮点之间的欧几里得距离,我们把式子化简可以得出一个不等式

根据不等式和三角形的性质,我们可以看出要想有最好的朋友,每3个人必须在一条直线上,最后所有人都在一条直线上,只能有

一对最好的朋

#include <cstdio>#include <vector>#include <cstring>#include <algorithm>typedef long long LL;using namespace std;const int maxn =200000 + 10;struct Child{    int s, r, id;    Child(){}    Child(int s, int r, int id) : s(s), r(r), id(id){}    bool operator < (const Child &rhs) const {        return s < rhs.s || (s == rhs.s && r < rhs.r);    }}c[maxn];int main(){    int n; scanf("%d", &n);    for(int i = 0; i < n; ++i) {        int s, r; scanf("%d%d", &s, &r);        c[i] = Child(s, r, i);    }    sort(c, c + n); vector<int> x, y;    for(int i = 1; i < n; ++i){        x.push_back(c[i].s - c[i - 1].s);        y.push_back(c[i].r - c[i - 1].r);    }    int len = x.size();    for(int i = 1; i < len; ++i){        if((LL)x[i - 1] * y[i] != (LL)x[i] * y[i - 1]){            printf("0\n"); return 0;        }    }    printf("1\n");    printf("%d %d\n", c[0].id + 1, c[n - 1].id + 1);    return 0;}

友,直接排序计算平行即可

0 0
原创粉丝点击