@VecMD
2016-07-12T20:29:17.000000Z
字数 1150
阅读 1741
被一道这么傻逼的题卡了这么久,不说了,我去切腹自尽了。
枚举一下谁先走比较好,走哪个点比较好。显然是走后走-先走差值最大的那个点(包括负数啊,兄弟!也没谁了)。然后再对B点进行贪心的选择,同上。
#include <cmath>
#include <cstdio>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
const int maxn = 100007;
int n;
double ccc;
typedef std::pair<double, double> Point;
Point ali, bre, bin, point[maxn];
double dist(Point const &a, Point const &b){
return sqrt((a.first - b.first)*(a.first - b.first)
+(a.second - b.second)*(a.second - b.second));
}
int go(Point p, double & ans){
int id = -1;
double temp = -9999999999.0 ;
for(int i = 1; i <= n; i ++){
double t1 = dist(p, point[i]) + dist(point[i], bin);
double t2 = 2 * dist(point[i], bin);
if(t2 - t1 > temp){
id = i;
ans = t1;
temp = t2 - t1;
}
}
ccc = std::max(ccc, temp);
return id;
}
double cal(Point const &p, Point const &q){
double res = 0.0, def = 0.0;
int id = go(p, res);
for(int i = 1; i <= n; i ++){
if(id == i) continue;
double t1, t2;
t1 = 2 * dist(point[i], bin);
t2 = dist(point[i], q) + dist(point[i], bin);
if(def < t1 - t2) def = t1 - t2;
res += t1;
}
return res - def;
}
int main()
{
std::cin >> ali.first >> ali.second;
std::cin >> bre.first >> bre.second;
std::cin >> bin.first >> bin.second;
std::cin >> n;
for(int i = 1; i <= n; i ++){
std::cin >> point[i].first >> point[i].second;
}
double ans = std::min(cal(ali, bre), cal(bre, ali));
printf("%.8f\n", ans);
}