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得时候 ...
随机推荐
- go 常见问题
以下是我在go项目中碰到问题 1. 如何只测试指定的test文件,而不是所有的单元测试都跑一遍. go tool vet -test -v src\github.com\astaxie\beego\c ...
- 离线安装 python 第三方库
离线安装 python 第三方库 首先你需要在联网的服务器上已经安装了一个第三方库,比如是paramiko,也就是说你已经执行了 pip install paramiko ,小提示: 如果在安 ...
- retain, copy, assign区别
1.retain, copy, assign区别 假设你用malloc分配了一块内存,并且把它的地址赋值给了指针a,后来你希望指针b也共享这块内存,于是你又把a赋值给(assign)了b.此时a 和b ...
- 搭建Selenium环境
1.下载并安装Python 此学习笔记使用Python语言进行开发,所以我已经安装了Python环境,我的Python版本为3.5.2: 2.安装selenium 因为我使用的Python3版本,在该 ...
- pycharm设置连接
https://blog.csdn.net/u013088062/article/details/50100121
- 【ARC062F】 Painting Graphs with AtCoDeer 点双连通分量+polya定理
Description 给定一张N点M边的无向图,每条边要染一个编号在1到K的颜色. 你可以对一张染色了的图进行若干次操作,每次操作形如,在图中选择一个简单环(即不经过相同点的环),并且将其颜色逆时针 ...
- C#/ASP.NET对URL中的中文乱码处理
前言:UTF-8中,一个汉字对应三个字节,GB2312中一个汉字占用两个字节. 不论何种编码,字母数字都不编码,特殊符号编码后占用一个字节. 1.直接在C#后台编码URL参数 引用类库:System. ...
- SpeechVoiceSpeakFlags枚举类型的详细解释
http://blog.csdn.net/zhou_xw6511/article/details/8313528
- vue从一个页面跳转到另一个页面并携带参数
1.需求: 点击商场跳转到商业体列表 解决方案: 元页面: a标签中添加跳转函数 <a class="orderBtn1 sIRicon2" href="javas ...
- Android 利用apache tomcat在自己的电脑上搭建服务器
1.什么叫服务器 装了服务器端的软件的那台电脑被称为服务器.常见的服务器的软件有apache tomcat. 2.Tomcat 介绍 tomcat是一种轻量级的web容器服务器,使用tomcat可以实 ...