Problem 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

3
10 10 5 20 20 5
10 10 10 20 20 10
10 10 5 20 10 5

 Sample Output

4
2
3

 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——————【两个圆的切线个数】的更多相关文章

  1. FZU 2213 Common Tangents(公切线)

    Description 题目描述 Two different circles can have at most four common tangents. The picture below is a ...

  2. FZU 2213 Common Tangents 第六届福建省赛

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2213 题目大意:两个圆,并且知道两个圆的圆心和半径,求这两个圆共同的切线有多少条,若有无数条,输出-1,其他条 ...

  3. FZU Problem 2213 Common Tangents

    其实是不太好意思往博客上放的,因为是一道巨水的题,但是我却错了一次,没有判断重合,放上还是为了警示自己,尽量不要在水题上罚时 #include<iostream> #include< ...

  4. 福建省赛-- Common Tangents(数学几何)

    Problem B Common Tangents Accept: 191    Submit: 608 Time Limit: 1000 mSec    Memory Limit : 32768 K ...

  5. 实验12:Problem D: 判断两个圆之间的关系

    Home Web Board ProblemSet Standing Status Statistics   Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...

  6. POJ 2546 Circular Area(两个圆相交的面积)

    题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...

  7. java求两个圆相交坐标

    最近由于项目需要,根据两个圆函数求出相交的坐标.实现代码如下,另感谢两圆求交点算法实现Java代码,虽然他所贡献的代码中存在问题,但仍有借鉴意义. 1.两个圆相交的数学求法 在中学数学中我们知道,一个 ...

  8. C++ 判断两个圆是否有交集

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <math.h> #include <easyx.h ...

  9. poj1375Intervals(点到圆的切线)

    链接 貌似这样的叫解析几何 重点如何求得过光源到圆的切线与地板的交点x坐标,可以通过角度及距离来算,如图, 根据距离和半径可以求得角度a.b.r,自然也可以求得d1,d2. 至于方向问题,在求r得时候 ...

随机推荐

  1. [.net 多线程]Semaphore信号量

    信号量(Semaphore)是一种CLR中的内核同步对象.与标准的排他锁对象(Monitor,Mutex,SpinLock)不同的是,它不是一个排他的锁对象,它与SemaphoreSlim,Reade ...

  2. Spring之BeanFactory与ApplicationConText

    :BeanFactory基本的工厂解析,管理,实例化所有容器内的bean的接口,spring中所有解析配置文件的类都直接或者间接实现该接口ApplicationContext接口implements ...

  3. Windowns DOS For 循环实例

    update_all.bat代码示例: @echo off echo ***************************************************************** ...

  4. 洛谷P3236 [HNOI2014]画框(最小乘积KM)

    题面 传送门 题解 我似乎连\(KM\)都不会打啊→_→ 和bzoj2395是一样的,只不过把最小生成树换成\(KM\)了.因为\(KM\)跑的是最大权值所以取个反就行了 //minamoto #in ...

  5. BZOJ 1061 [Noi2008]志愿者招募(费用流)

    题目描述 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能完成,其中第i ...

  6. SpringMVC的简单介绍及使用

    一.简介 1.SpringMVC和Spring的关系: >软件开发的三层架构: web层[表示层.表现层]---->Service层---->Dao[DataBase Access ...

  7. Leetcode 8. String to Integer (atoi) atoi函数实现 (字符串)

    Leetcode 8. String to Integer (atoi) atoi函数实现 (字符串) 题目描述 实现atoi函数,将一个字符串转化为数字 测试样例 Input: "42&q ...

  8. SDUT OJ 多项式求和

    多项式求和 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 多项式描述 ...

  9. Vue 环境配置

    最开始摸element的时候,像盲人摸象,完全没有头绪. https://panjiachen.github.io/vue-element-admin-site/zh/guide/essentials ...

  10. 浅谈C#中的委托、事件与异步

    从刚接触c#编程到现在,差不多快有一年的时间了.在学习过程中,有很多地方始终似是而非,直到最近才弄明白. 本文将先介绍用法,后评断功能. 一.委托 基本用法: 1.声明一个委托类型.委托就像是‘类'一 ...