反演

适用题目特征

题目中存在多个圆/直线之间的相切关系的情况,可利用反演简化计算。

原理

1 圆A外的点的反演点在圆A内,反之亦然;圆A上的点的反演点为其自身。
2 不过点P的圆A,其反演图形是不过点P的圆。
3 过点P的圆A,其反演图形是不过点P的直线。
4 两个图形相切,则他们的反演图形也相切。

例题

HDU 4774
代码如下

/*
HDU 4773 
*/
#define method_1
#ifdef method_1
/*

*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define D(x) cout<<#x<<" = "<=(s);i--)
using namespace std;
typedef long long ll;
typedef pairpii;
const int maxn=4;
const double eps=1e-8;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f;
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    const bool operator<(const Point &h) const{return (x0){
        double ang=acos(rsum/sqrt(d2));
        a[cnt]=A.point(base+ang),b[cnt]=B.point(pi+base+ang),++cnt;
        a[cnt]=A.point(base-ang),b[cnt]=B.point(pi+base-ang),++cnt;
    }
    return cnt;
}
Circle Inversion_C2C(Point O,double R,Circle A){
    double OA=len(A.c-O);
    double RB = 0.5 * ((1 / (OA - A.r)) - (1 / (OA + A.r))) * R * R;
    double OB = OA * RB / A.r;
    double Bx = O.x + (A.c.x - O.x) * OB / OA;
    double By = O.y + (A.c.y - O.y) * OB / OA;
    return Circle(Point(Bx, By), RB);
}
Circle Inversion_L2C(Point O,double R,Point A,Vec v) {
    Point P=getLineProjection(O,A,A+v);
    double d=len(O-P);
    double RB=R*R/(2*d);
    Vec VB=(P-O)/d*RB;
    return Circle(O+VB,RB);
}  
bool theSameSideOfLine(Point A,Point B,Point S,Vec v) {
    return dcmp(cross(A-S,v))*dcmp(cross(B-S,v))>0;
} 
int T;
void solve(){
    Circle A,B;Point P;
    cin>>A.c.x>>A.c.y>>A.r;
    cin>>B.c.x>>B.c.y>>B.r;
    cin>>P.x>>P.y;
    Circle NA=Inversion_C2C(P,10,A);
    Circle NB=Inversion_C2C(P,10,B);
    Point LA[maxn],LB[maxn];
    Circle ansC[maxn];
    int q=getTangents(NA,NB,LA,LB),ans=0;
    rep0(i,0,q){
        if(theSameSideOfLine(NA.c,NB.c,LA[i],LB[i]-LA[i])){
            if(!theSameSideOfLine(P,NB.c,LA[i],LB[i]-LA[i])) continue;
            ansC[ans++]=Inversion_L2C(P,10,LA[i],LB[i]-LA[i]);
        }
    } 
    cout<>T;
    while(T--) solve();
    return 0;
}
#endif
#ifdef method_2
/*

*/

#endif
#ifdef method_3
/*

*/

#endif

你可能感兴趣的:(反演)