FZU 2213——Common Tangents——————【两个圆的切线个数】
Accept: 7 Submit: 8
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Two different circles can have at most four common tangents.
The picture below is an illustration of two circles with four common tangents.

Now given the center and radius of two circles, your job is to find how many common tangents between them.
Input
The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).
For each test case, there is one line contains six integers x1 (−100 ≤ x1 ≤ 100), y1 (−100 ≤ y1 ≤ 100), r1 (0 < r1 ≤ 200), x2 (−100 ≤ x2 ≤ 100), y2 (−100 ≤ y2 ≤ 100), r2 (0 < r2 ≤ 200). Here (x1, y1) and (x2, y2) are the coordinates of the center of the first circle and second circle respectively, r1 is the radius of the first circle and r2 is the radius of the second circle.
Output
For each test case, output the corresponding answer in one line.
If there is infinite number of tangents between the two circles then output -1.
Sample Input
Sample Output
Source
第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
struct Circle{
double x,y,r;
};
int getTangents(Circle A,Circle B){
int cnt = 0;
if(A.r < B.r){ swap(A,B); } //固定A为大圆
int d2 = (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y); //圆心距的平方
int rdiff = A.r - B.r; //半径差
int rsum = A.r + B.r; //半径和
if(d2 < rdiff*rdiff) return 0; //内含
double base = atan2(B.y-A.y,B.x-A.x); //求出两个圆心所在直线与x轴正方向的夹角
if(d2 == 0 && A.r == B.r) return -1; //两个圆相等,无数条切线
if(d2 == rdiff*rdiff){ //内切,一条切线
cnt++;
return 1;
}
double ang = acos((A.r-B.r)/sqrt(d2));
//两条外公切线
cnt++; cnt++;
if(d2 == rsum*rsum){ //外切,一条内公切线
cnt++;
}else if(d2 > rsum*rsum){ //相离,两条内公切线
cnt++; cnt++;
}
return cnt;
}
int main(){
int T;
Circle r1, r2;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf%lf%lf",&r1.x,&r1.y,&r1.r,&r2.x,&r2.y,&r2.r);
int ans = getTangents(r1,r2);
printf("%d\n",ans);
}
return 0;
}
FZU 2213——Common Tangents——————【两个圆的切线个数】的更多相关文章
- FZU 2213 Common Tangents(公切线)
Description 题目描述 Two different circles can have at most four common tangents. The picture below is a ...
- FZU 2213 Common Tangents 第六届福建省赛
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2213 题目大意:两个圆,并且知道两个圆的圆心和半径,求这两个圆共同的切线有多少条,若有无数条,输出-1,其他条 ...
- FZU Problem 2213 Common Tangents
其实是不太好意思往博客上放的,因为是一道巨水的题,但是我却错了一次,没有判断重合,放上还是为了警示自己,尽量不要在水题上罚时 #include<iostream> #include< ...
- 福建省赛-- Common Tangents(数学几何)
Problem B Common Tangents Accept: 191 Submit: 608 Time Limit: 1000 mSec Memory Limit : 32768 K ...
- 实验12:Problem D: 判断两个圆之间的关系
Home Web Board ProblemSet Standing Status Statistics Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...
- POJ 2546 Circular Area(两个圆相交的面积)
题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...
- java求两个圆相交坐标
最近由于项目需要,根据两个圆函数求出相交的坐标.实现代码如下,另感谢两圆求交点算法实现Java代码,虽然他所贡献的代码中存在问题,但仍有借鉴意义. 1.两个圆相交的数学求法 在中学数学中我们知道,一个 ...
- C++ 判断两个圆是否有交集
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <math.h> #include <easyx.h ...
- poj1375Intervals(点到圆的切线)
链接 貌似这样的叫解析几何 重点如何求得过光源到圆的切线与地板的交点x坐标,可以通过角度及距离来算,如图, 根据距离和半径可以求得角度a.b.r,自然也可以求得d1,d2. 至于方向问题,在求r得时候 ...
随机推荐
- LogNet4
ASP.Net MVC 项目中添加LogNet4 1,创建ASP.NET MVC项目 2,NuGet或者直接下载log4net.dll 并安装 3 在配置文件 web.config 加入 如下代码 & ...
- linux下利用httpd搭建tomcat集群,实现负载均衡
公司使用运营管理平台是单点tomcat,使用量大,或者导出较大的运营数据时,会造成平台不可用,现在需要搭建tomcat集群,调研后,决定使用apache的httpd来搭建tomcat集群.以下是搭建步 ...
- ubuntu14.04,安装Chrome(谷歌浏览器)
Linux:ubuntu14.04 一直都很喜欢谷歌浏览器,进入linux怎么能没有? 安装方法:谷歌浏览器官方下载的ubuntu版本,下载后点击即可安装. 下载地址:http://download. ...
- php代码审计6审计xss漏洞
跨站脚本攻击(Cross Site Scripting)是指攻击者利用网站程序对用户输入过滤不足,输入可以显示在页面上对其他用户造成影响的html代码,从而盗取用户资料,利用用户身份进行某种动作或者对 ...
- 【bzoj2500】幸福的道路 树形dp+单调队列
Description 小T与小L终于决定走在一起,他们不想浪费在一起的每一分每一秒,所以他们决定每天早上一同晨练来享受在一起的时光. 他们画出了晨练路线的草图,眼尖的小T发现可以用树来描绘这个草图. ...
- uoj #297. 【CTSC2017】密钥
#297. [CTSC2017]密钥 一个密钥是一个长度为 n=2k+1n=2k+1 的字符串,它包含 11 个字母X.kk 个字母 A 和 kk 个字母 B.例如 k=3k=3 时,BAXABAB ...
- EL表达式的语法与应用
EL(是Expression Language的缩写),使用EL对JSP输出进行优化,可以使得页面结构更加清晰,代码可读性高,也更加便于维护. EL表达式的语法: 语法:$(EL 表达式) $ 和 ...
- Flume自定义拦截器(Interceptors)或自带拦截器时的一些经验技巧总结(图文详解)
不多说,直接上干货! 一.自定义拦截器类型必须是:类全名$内部类名,其实就是内部类名称 如:zhouls.bigdata.MySearchAndReplaceInterceptor$Builder 二 ...
- OEL6.8安装虚拟带库模拟器
最近在虚拟机下搭建了一个OSB备份环境,其中使用到了虚拟带库,以下是虚拟带库的配置过程,简要记录之. 1.下载虚拟带库的源码(mhvtl-2016-03-10.tgz). 2.解压缩源码. # cd ...
- [SP1825] Free tour II
/* ----------------------- [题解] https://www.luogu.org/blog/IRving1-1/solution-sp1825 --------------- ...