题意:给定 n 个人,每个人两个值s, r,要满足,p(v, u) = sqrt((sv − su)^2 + (rv − ru)^2), p(v,u,w) = (p(v,u) + p(v,w) + p(u,w)) / 2
要求找出p(v, u) ≥ p(v,u,w) 的对数,其中w是除u,v外,任意的人。
析:化简一下这个表达式,这很明显是两边之和小于等于第三边,好像挺熟悉啊,对,三角形是两边之和大于第三边,现在是小于,不可能,只能是等于,要想等于,
那么只是共线了,并且w是任何人,所以这些点全部都要共线。并且两端的人就是答案,并且只有一对。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include <cmath> #include <stack> #define frer freopen("in.txt", "r", stdin) #define frew freopen("out.txt", "w", stdout) using namespace std; typedef long long LL; typedef pair<int, int> P; const int INF = 0x3f3f3f3f; const double inf = 0x3f3f3f3f3f3f; const double PI = acos(-1.0); const double eps = 1e-8; const int maxn = 2e5 + 5; const int mod = 1e8; const char *mark = "+-*"; const int dr[] = {-1, 0, 1, 0}; const int dc[] = {0, 1, 0, -1}; int n, m; const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; inline int Min(int a, int b){ return a < b ? a : b; } inline int Max(int a, int b){ return a > b ? a : b; } inline LL Min(LL a, LL b){ return a < b ? a : b; } inline LL Max(LL a, LL b){ return a > b ? a : b; } inline bool is_in(int r, int c){ return r >= 0 && r < n && c >= 0 && c < m; } struct node{ LL x, y; int id; node() { } node(LL xx, LL yy) : x(xx), y(yy){ } bool operator < (const node &p) const{ return x < p.x || (x == p.x && y < p.y); } }; node a[maxn]; int main(){ while(scanf("%d", &n) == 1){ LL x, y; for(int i = 0; i < n; ++i){ scanf("%I64d %I64d", &x, &y); a[i] = node(x, y); a[i].id = i+1; } bool ok = true; for(int i = 2; i < n; ++i) if((a[i-1].x-a[i].x)*(a[i-2].y-a[i].y) != (a[i-1].y-a[i].y)*(a[i-2].x-a[i].x)){ ok = false; break;} if(!ok){ printf("0\n"); continue; } sort(a, a+n); printf("1\n%d %d\n", a[0].id, a[n-1].id); } return 0; }