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得时候 ...
随机推荐
- NSKeyedArchiver数据归档
前言 在 OC 语言中,归档是一个过程,即用某种格式来保存一个或多个对象,以便以后还原这些对象. 通常,这个过程包括将(多个)对象写入文件中,以便以后读取该对象.可以使用归档的方法进行对象的深复制. ...
- git you need to resolve your current index first 解决办法
当使用git checkout 切换分支时会提示you need to resolve your current index first,使用如下命令即可解决. $ git reset --merge
- Spring Boot多数据源
我们在开发过程中可能需要用到多个数据源,我们有一个项目(MySQL)就是和别的项目(SQL Server)混合使用了.其中SQL Server是别的公司开发的,有些基本数据需要从他们平台进行调取,那么 ...
- PS基本操作汇总(持续更新)
一.放大缩小图片:ctrl+/- 二.缩小gif:ps时打开后,web格式保存,里面点出优化面板,选gif格式,颜色数减小,如128,损耗30,图片大小也可调整,比如调整为50%,点击预览,可在浏览器 ...
- 洛谷P3122 [USACO15FEB]圈住牛Fencing the Herd(计算几何+CDQ分治)
题面 传送门 题解 题目转化一下就是所有点都在直线\(Ax+By-C=0\)的同一侧,也就可以看做所有点代入\(Ax+By-C\)之后的值符号相同,我们只要维护每一个点代入直线之后的最大值和最小值,看 ...
- SDUT OJ 数据结构实验之排序八:快速排序
数据结构实验之排序八:快速排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 给定N ...
- SDUT OJ 数据结构实验之链表五:单链表的拆分
数据结构实验之链表五:单链表的拆分 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- 深入解析Close()和Dispose()的区别
很多人都认为Close()方法内部会调用Dispose()方法,所以并没有本质的区别!实际上这个看法不是很准确,对有 些类来说,的确Close()和Dispose()没有本质区别,但是对有些类来说并非 ...
- 2.1、Softmax Regression模型
Softmax Regression模型 由于Logistics Regression算法复杂度低,容易实现等特点,在工业中的到广泛的使用,但是Logistics Regression算法主要用于处理 ...
- C++_类入门4-String类
很多应用程序都需要处理字符串.C语言在string.h(C++中为cstring)中提供了一系列的字符串函数,很多早期的C++实现为处理字符串提供了自己的类. string类是由头文件string支持 ...