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
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.
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.
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 any order is OK. Your answer
will be accepted if your absolute error for each number is no more than 10-4.
1
12 10 1 8 10 1 10 10
2
10.00000000 8.50000000 1.50000000
10.00000000 11.50000000 1.50000000HintThis problem is special judged.
hdu 4773 Problem of Apollonius的更多相关文章
- 【HDU】4773 Problem of Apollonius
题意 给定相离的两个圆(圆心坐标以及半径)以及圆外的一个定点\(P\),求出过点\(P\)的且与已知的两个圆外切的所有圆(输出总数+圆心.半径). 分析 如果强行解方程,反正我是不会. 本题用到新姿势 ...
- 【 HDU4773 】Problem of Apollonius (圆的反演)
BUPT2017 wintertraining(15) #5G HDU - 4773 - 2013 Asia Hangzhou Regional Contest problem D 题意 给定两个相离 ...
- HDU 6343.Problem L. Graph Theory Homework-数学 (2018 Multi-University Training Contest 4 1012)
6343.Problem L. Graph Theory Homework 官方题解: 一篇写的很好的博客: HDU 6343 - Problem L. Graph Theory Homework - ...
- hdu String Problem(最小表示法入门题)
hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...
- HDU 6343 - Problem L. Graph Theory Homework - [(伪装成图论题的)简单数学题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 5687 Problem C 【字典树删除】
传..传送:http://acm.hdu.edu.cn/showproblem.php?pid=5687 Problem C Time Limit: 2000/1000 MS (Java/Others ...
- HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)
6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...
- HDU 6336.Problem E. Matrix from Arrays-子矩阵求和+规律+二维前缀和 (2018 Multi-University Training Contest 4 1005)
6336.Problem E. Matrix from Arrays 不想解释了,直接官方题解: 队友写了博客,我是水的他的代码 ------>HDU 6336 子矩阵求和 至于为什么是4倍的, ...
- HDU 5687 Problem C(Trie+坑)
Problem C Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
随机推荐
- log4N配置方式
方式一. <log4net> <!-- 启动日志 --> <appender name="PayAppender" type="log4ne ...
- Clang 与 LLVM
我们在iOS调试中经常会看到Clang这个,那么Clang到底是什么呢?我们来简单了解一下. Clang是一个C.C++.OC语言的轻量级编译器.源代码发布于BSD协议下.Clang是由C++编写,基 ...
- caffe之(二)pooling层
在caffe中,网络的结构由prototxt文件中给出,由一些列的Layer(层)组成,常用的层如:数据加载层.卷积操作层.pooling层.非线性变换层.内积运算层.归一化层.损失计算层等:本篇主要 ...
- linux线程(一)基本应用
有感而发(可以直接忽略~):每次要用到线程,都要在网上重新学下基础,例子倒是不少:一种是排版好,讲的不全又不是自己想要的:一种是排版不好,直接略过了.两者兼有的又要苦苦寻找,所以还是自己总结了,觉得每 ...
- paip.php eclipse output echo 乱码
paip.php eclipse output echo 乱码 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.c ...
- 4.android.mk编写规范
Android.mk是Android提供的一种makefile文件,用来指定诸如编译生成so库名.引用的头文件目录.需要编译的.c/.cpp文件和.a静态库文件等.要掌握jni,就必须熟练掌握Andr ...
- Handler sendMessage 与 obtainMessage (sendToTarget)
这篇文章讲的很好: http://www.cnblogs.com/android007/archive/2012/05/10/2494766.html 两种用法: 1. private void se ...
- XP中IIS“HTTP 500 - 内部服务器错误”解决方法
我先把主要过程叙述一下,叙述完有每个问题的具体操作方法. 今天我在XP上安装IIS,运行网站出现"HTTP 500 - 内部服务器错误". 打开HTML没有问题,打开ASP文件时就 ...
- redhat 6.5 使用其它Linux镜像源的yum源
最近在虚拟机里装了rhel_6.5_x86_64,发现竟然不自带g++,没办法只好 “yum install gcc-c++”,无奈失败,原因是redhat的yum是收费的... 于是打算怒装其它免费 ...
- JS思维导图