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.

两个不同的圆最多可以有4种公切线。

下图表示两个圆的4种公切线。

现在分别给你两个圆的圆心和半径,求他们之间有几条公切线。

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.

输入的首行是一个整数T,表示测试样例的数量。(1 <= T <= 50)。

每个测试样例都是一行6个整数,x1 (−100 ≤ x1 ≤ 100), y1 (−100 ≤ y1 ≤ 100), r1 (0 < r1 ≤ 200), x2 (−100 ≤ x2 ≤ 100), y2 (−100 ≤ y2 ≤ 100), r2 (0 < r2 ≤ 200)。

其中(x1, y1)与(x2, y2)分别是第一个圆与第二个圆的圆心,r1、r2分别是第一个圆与第二个圆的半径。

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.

每个测试样例的结果输出一行。

如果存在无数条公切线则输出-1。

Sample Input - 输入样例

Sample Output - 输出样例

3

10 10 5 20 20 5

10 10 10 20 20 10

10 10 5 20 10 5

4

2

3

【题解】

根据圆的位置关系分情况即可。

1. 圆心距>半径和,相离,4条公切线。

2. 圆心距==半径和,外切,3条公切线。

3. 半径差<圆心距<半径和,相交,2条公切线。

4. 圆心距==半径差,圆心不等,内切,1条公切线;圆心相等,重合,无数条公切线。

5. 圆心距<半径差,内含,0条公切线。

接着用平方表示就能解决误差的问题,直接可用int进行比较。

【代码 C++】

 #include<cstdio>
#include<cstring>
int main(){
int t, x1, y1, r1, x2, y2, r2, c_distance, r_sum, r_difference;
scanf("%d", &t);
while (t--){
scanf("%d%d%d%d%d%d", &x1, &y1, &r1, &x2, &y2, &r2);
c_distance = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
r_sum = (r1 + r2)*(r1 + r2);
r_difference = r_sum - (r1*r2 << );
if (c_distance > r_sum) puts("");//相离
else if (c_distance == r_sum) puts("");//外切
else if (r_difference < c_distance &&c_distance < r_sum) puts("");//相交
else if (c_distance == r_difference){
if (x1 ^ x2 | y1 ^ y2) puts("");//内切
else puts("-1");//重合
}
else puts("");//内含
}
return ;
}

FZU 2213

FZU 2213 Common Tangents(公切线)的更多相关文章

  1. FZU 2213——Common Tangents——————【两个圆的切线个数】

    Problem 2213 Common Tangents Accept: 7    Submit: 8Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  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. 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)

    from:piaocoder Common Tangents(两圆之间的公公切线) 题目链接: http://acm.fzu.edu.cn/problem.php?pid=2213 解题思路: 告诉你 ...

  6. UVA - 10674-Tangents

     题意:给出两个圆,求它们的公切线,并依照一定格式输出 做法:模拟 代码: #include<iostream> #include<map> #include<str ...

  7. Circles and Pi

    Circles and Pi Introduction id: intro-1 For as long as human beings exist, we have looked to the sky ...

  8. UVa 10674 (求两圆公切线) Tangents

    题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...

  9. Socket聊天程序——Common

    写在前面: 上一篇记录了Socket聊天程序的客户端设计,为了记录的完整性,这里还是将Socket聊天的最后一个模块--Common模块记录一下.Common的设计如下: 功能说明: Common模块 ...

随机推荐

  1. 在TVideoGrabber中如何在预览时设置相机属性

    在使用TVideoGrabber进行预览时,如何设置相机的属性呢?比如曝光.对比度.亮度等. 下面来看一下,如何通过编程来调整这些设置: ——通过指定VideoDevice属性(在VideoDevic ...

  2. Pascal's Triangle II

    class Solution { public: vector<int> getRow(int rowIndex) { vector<int> v; ) return v; v ...

  3. 两个升序链表的合并 Merge Two Sorted Lists 【 leetcode】

    class Solution {public:   ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {   ListNode *p; ListN ...

  4. plsql日期乱码

    乱码状况如截图: 控制面板\所有控制面板项\系统\高级系统设置\环境变量, 设置系统变量,变量名:NLS_LANG,变量值:Simplified Chinese_China.AL32UTF8改为SIM ...

  5. NSDictionary to jsonString || 对象转json格式

    -(NSString*)DataTOjsonString:(id)object { NSString *jsonString = nil; NSError *error; NSData *jsonDa ...

  6. ThreadLocal深入理解一

    转载:http://www.cnblogs.com/dolphin0520/p/3920407.html 想必很多朋友对ThreadLocal并不陌生,今天我们就来一起探讨下ThreadLocal的使 ...

  7. Spring的BeanFactoryPostProcessor和BeanPostProcessor

    转载:http://blog.csdn.net/caihaijiang/article/details/35552859 BeanFactoryPostProcessor和BeanPostProces ...

  8. linux ftp服务

    1 安装ftp服务 [root@localhost ~]# yum install vsftpd 启动:service vsftpd start 查看状态:systemctl |grep vsftpd ...

  9. Jenkins构建Git manager服务器的源码

    1,下载scm manager 源码库管理,下载后解压即可: 2,运行bin目录下的scm-server.bat文件,启动服务: 3,建议将scm-server放在git客户端的安装目录下,方便管理 ...

  10. grails的layouts模板页面使用

    使用方式1: layouts文件夹下新建文件,名称和Controller名称相同,例如UserController,layouts下面创建user.gsp,此时,user站点下所有的页面都将套用 us ...