HDU 6097 Mindis (计算几何)

题意:给一个圆C和圆心O,P、Q是圆上或圆内到圆心距离相等的两个点,在圆上取一点D,求|PD| + |QD|的最小值

析:首先这个题是可以用三分过的,不过也太,。。。。

官方题解:

很不幸不总是中垂线上的点取到最小值,考虑点在圆上的极端情况。

做P点关于圆的反演点P',OPD与ODP'相似,相似比是|OP| : r。

Q点同理。

极小化PD+QD可以转化为极小化P'D+Q'D。

当P'Q'与圆有交点时,答案为两点距离,否则最优值在中垂线上取到。

时间复杂度 O(1)O(1)

也有代数做法,结论相同。

优秀的黄金分割三分应该也是可以卡过的。

主要是可以先通过反演来获得P',Q‘,坐标,可以通过人为再构造一个横纵坐标的比例等于OP和OP'的比来计算,然后再考虑是不是与圆相交,这个可以用求中点,带入圆的方程得到,如果在外面,先可以求出P,Q的中点E,然后能求OE,PE,就可以求得DE,最后再求那PP'即可。

代码如下:

#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>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10000 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
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 bool is_in(int r, int c){
  return r >= 0 && r < n && c >= 0 && c < m;
}

double dist(double x1, double y1, double x2 = 0.0, double y2 = 0.0){
  return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}


int main(){
  int T;  cin >> T;
  while(T--){
    double xp, yp, xq, yq, r;
    scanf("%lf", &r);
    scanf("%lf %lf %lf %lf", &xp, &yp, &xq, &yq);
    double op = dist(xp, yp);
    double oq = dist(xq, yq);
    double opp = r * r / op;
    double oqq = r * r / oq;
    double xpp = opp * xp / op;
    double xqq = oqq * xq / oq;
    double ypp = opp * yp / op;
    double yqq = oqq * yq / oq;
    double avx = (xpp + xqq) / 2.0;
    double avy = (ypp + yqq) / 2.0;
    if(avx * avx + avy * avy <= r * r){
      printf("%.10f
", dist(xpp, ypp, xqq, yqq) * op / r);
      continue;
    }
    avx = (xp + xq) / 2.0;
    avy = (yp + yq) / 2.0;
    double oav = r - dist(avx, avy);
    double tmp = dist(xp, yp, avx, avy);
    double ans = sqrt(tmp*tmp + oav*oav);
    printf("%.10f
", ans*2.0);
  }
  return 0;
}

  

原文地址:https://www.cnblogs.com/dwtfukgv/p/7347732.html