hdu 4773 Problem of Apollonius

莫名其妙就AC了……

圆的反演……

神马是反演?

快去恶补奥数……

#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-9;
int dcmp(double x){return fabs(x)<eps?0:x<0?-1:1;}
struct dot
{
    double x,y;
    dot(){}
    dot(double a,double b){x=a;y=b;}
    dot operator +(dot a){return dot(x+a.x,y+a.y);}
    dot operator -(dot a){return dot(x-a.x,y-a.y);}
    dot operator *(double a){return dot(x*a,y*a);}
    double operator *(dot a){return x*a.y-y*a.x;}
    dot operator /(double a){return dot(x/a,y/a);}
    double operator /(dot a){return x*a.x+y*a.y;}
    bool operator ==(dot a){return x==a.x&&y==a.y;}
    void in(){scanf("%lf%lf",&x,&y);}
    void out(){printf("%f %f\n",x,y);}
    dot norv(){return dot(-y,x);}
    dot univ(){double a=mod();return dot(x/a,y/a);}
    dot ro(double a){return dot(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a));}
    double mod(){return sqrt(x*x+y*y);}
    double dis(dot a){return sqrt(pow(x-a.x,2)+pow(y-a.y,2));}
};
struct cir
{
    dot o;
    double r;
    cir(){}
    cir(dot a,double b){o=a;r=b;}
    void in(){o.in();scanf("%lf",&r);}
};
struct seg
{
    dot s,e;
    seg(){}
    seg(dot a,dot b){s=a;e=b;}
};
cir sivs(dot a,dot b,dot c)
{
    dot dir,a1,b1;
    double t,d,w;
    t=fabs((b-a)*(c-a));
    d=a.dis(b);
    t/=d;
    w=0.5/t;
    dir=(b-a).norv();
    a1=c+dir*(w/d);
    b1=c-dir*(w/d);
    if(fabs((b-a)*(a1-a))<fabs((b-a)*(b1-a)))
        return cir(a1,w);
    else
        return cir(b1,w);
}
cir civs(cir a,dot b)
{
    cir c;
    double t,x,y,s;
    t=a.o.dis(b);
    x=1.0/(t-a.r);
    y=1.0/(t+a.r);
    c.r=(x-y)/2.0;
    s=(x+y)/2.0;
    c.o=b+(a.o-b)*(s/t);
    return c;
}
seg se[2];
void comseg(dot a,double r1,dot b,double r2)
{
    double ang;
    ang=acos((r1-r2)/a.dis(b));
    se[0].s=a+(b-a).ro(ang).univ()*r1;
    se[1].s=a+(b-a).ro(-ang).univ()*r1;
    ang=pi-ang;
    se[0].e=b+(a-b).ro(-ang).univ()*r2;
    se[1].e=b+(a-b).ro(ang).univ()*r2;
}
int main()
{
    int T,cnt,i;
    cir a,b,a1,b1,ans[2];
    dot c;
    scanf("%d",&T);
    while(T--)
    {
        a.in();
        b.in();
        c.in();
        a1=civs(a,c);
        b1=civs(b,c);
        comseg(a1.o,a1.r,b1.o,b1.r);
        cnt=0;
        for(i=0;i<2;i++)
            if(dcmp((a1.o-se[i].s)*(se[i].e-se[i].s))==dcmp((c-se[i].s)*(se[i].e-se[i].s)))
                if(dcmp((b1.o-se[i].s)*(se[i].e-se[i].s))==dcmp((c-se[i].s)*(se[i].e-se[i].s)))
					ans[cnt++]=sivs(se[i].s,se[i].e,c);
        printf("%d\n",cnt);
        for(i=0;i<cnt;i++)
            printf("%.8f %.8f %.8f\n",ans[i].o.x,ans[i].o.y,ans[i].r);
    }
}

Problem of Apollonius

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 551    Accepted Submission(s): 124

Special Judge

Problem Description

  Apollonius of Perga (ca. 262 BC - ca. 190 BC) was a Greek geometer and astronomer. In his noted work Epaphai, he posed and solved such a problem: constructing circles that are tangent to three given circles in a plane. Two tangent
circles can be internally or externally tangent to each other, thus Apollonius‘s problem generically have eight solutions.

  Now considering a simplified case of Apollonius‘s problem: constructing circles that are externally tangent to two given circles, and touches a given point(the given point must be on the circle which you find, can‘t be inside the circle). In addition, two
given circles have no common points, and neither of them are contained by the other, and the given point is also located strictly outside the given circles. You should be thankful that modern mathematics provides you with plenty of useful tools other than
euclidean geometry that help you a lot in this problem.

Input

  The first line of input contains an integer T (T ≤ 200), indicating the number of cases.

  Each ease has eight positive integers x1, y1, r1, x2, y2, r2, x3, y3 in a single line, stating two circles whose centres are (x1, y1), (x2, y2) and radius are r1 and r2 respectively, and a point located at (x3, y3). All integers are no larger than one hundred.

Output

  For each case, firstly output an integer S, indicating the number of solutions.

  Then output S lines, each line contains three float numbers x, y and r, meaning that a circle, whose center is (x, y) and radius is r, is a solution to this case. If there are multiple solutions (S > 1), outputing them in&nbsp;any order is OK. Your answer
will be accepted if your absolute error for each number is no more than 10-4.

Sample Input

1
12 10 1 8 10 1 10 10

Sample Output

2
10.00000000 8.50000000 1.50000000
10.00000000 11.50000000 1.50000000

Hint

This problem is special judged.


 

Source

2013 Asia Hangzhou Regional Contest

时间: 2024-10-31 22:24:22

hdu 4773 Problem of Apollonius的相关文章

HDU 4773 Problem of Apollonius——圆反演

题面 HDU4773 解析  大概是圆反演的模板吧. 以点$P(x3, y3)$为反演中心,任意长为反演半径,将两个已知圆反演,设反演后的圆为$A'$, $B'$,所求圆反演后为一条直线,根据题目中的要求,该直线为两圆的外公切线.因此我们只需要求出两圆的外公切线即可. 然后会发现WA了,因为题目中还有一个要求,所求圆要外切于两圆,即反演变换后反演中心$P$和$A'$的圆心要在同侧. 还有一个我一开始做错了的地方,原来的圆心$O$反演后就不是新的圆心了!!!可以连接$PO$,求其与圆的两个交点,两

HDU 4910 Problem about GCD

Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 77 Problem Description Given integer m. Find multiplication of all 1<=a<=m such gcd(a, m)=1 (cop

HDU 2256 Problem of Precision (矩阵快速幂)

HDU 2256 Problem of Precision (矩阵快速幂) ACM 题目地址:HDU 2256 Problem of Precision 题意: 给出一个式子,求值. 分析: 推起来最后那步会比较难想. 具体过程见: 表示共轭只听说过复数的和图的... 这构题痕迹好明显... 跟基友开玩笑说:如果遇到这种题,推到Xn+Yn*sqrt(6)这步时,打表最多只能打到10就爆int了,这是输出正解和Xn,说不定眼神好能发现ans = Xn * 2 - 1呢.= =... 代码: /*

hdu 4910 Problem about GCD(数论)

题目连接:hdu 4910 Problem about GCD 题目大意:给定M,判断所有小于M并且和M互质的数的积取模M的值. 解题思路:有个数论的结论,若为偶数,M=M/2. 可以写成M=pk,即只有一种质因子时,答案为M-1,否则为1.特殊情况为4的倍数,不包括4. 首先用1e6以内的素数去试除,如果都不可以为p,那么对大于1e6的情况判断一下是否为素数,是素数也可以(k=1),否则开方计算,因为M最大为1e18,不可能包含3个大于1e6的质因子. #include <cstdio> #

HDU 4910 Problem about GCD(米勒拉宾)

HDU 4910 Problem about GCD 题目链接 题意:给定一个数字,求出1 - n之间与他互质的数的乘积mod n 思路:看了网上别人找出来的规律,原文链接 然后由于这题的n很大,也没法直接判定,可以这样搞,先去试10^6以内的素数,判断可不可以,如果不行,再利用米勒拉宾判下是否是素数,如果不是的话,把这个数字开根在平方,判断是不是完全平方数,这样做的原因是数字最大10^18,如果没有10^6以内的质因子,又不是质数的话,那么他最多只能包含2个质因子了,那么如果他不是一个完全平方

hdu String Problem(最小表示法入门题)

hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <string> using namespace std; const int N = 10010; int n; char s[105]; map<

hdu 5685 Problem A(2016&quot;百度之星&quot; - 资格赛(Astar Round1)——线段树)

题目链接:acm.hdu.edu.cn/showproblem.php?pid=5685 Problem A Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 564    Accepted Submission(s): 236 Problem Description 度熊手上有一本字典存储了大量的单词,有一次,他把所有单词组成了一个很长

HDU 5688 Problem D map

Problem D Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 394    Accepted Submission(s): 273 Problem Description 度熊所居住的 D 国,是一个完全尊重人权的国度.以至于这个国家的所有人命名自己的名字都非常奇怪.一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的每

hdu 2256 Problem of Precision

Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1225    Accepted Submission(s): 730 Problem Description Input The first line of input gives the number of cases, T. T test ca