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. 根据linux内核源码查找recv返回EBADF(errno 9)的原因

    linux的内核版本是2.6.18,x86_64. man里的解释是: EBADF The argument s is an invalid descriptor 我的模拟测试环境是: 前端loadr ...

  2. 解析XML的四种方式

    四种操作xml的方式: SAX, DOM, JDOM , DOM4J的比较 1. 介绍 1)DOM(JAXP Crimson解析器)         DOM是用与平台和语言无关的方式表示XML文档的官 ...

  3. CDN流量放大攻击思路

    首先,为了对CDN进行攻击,我们必须清楚CDN的工作原理,这里我们再来简单介绍一下CDN的工作模型. CDN的全称是Content Delivery Network(内容分发网络),通过在网络各处的加 ...

  4. 如何修复损坏的MySQL数据表

    id=164 由于断电或非正常关机而导致MySQL数据库出现错误是非常常见的问题.有两种方法,一种方法使用mysql的check table和repair table 的sql语句,另一种方法是使用M ...

  5. zabbix自定义监控tcp连接数

    首先在客户端修改配置文件 # vim /usr/local/zabbix/etc/zabbix_agentd.conf UnsafeUserParameters=1 UserParameter=tcp ...

  6. linux配置java环境变量(详细)【转】

    转自:http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html 一. 解压安装jdk 在shell终端下进入jdk-6u14-linux ...

  7. html5 canvas 笔记三(绘制文本和图片)

    绘制文本 fillText(text, x, y [, maxWidth])   在指定的(x,y)位置填充指定的文本,绘制的最大宽度是可选的. strokeText(text, x, y [, ma ...

  8. 2.1:你的第一个AngularJS App

    本章,带你体验一个简单的开发流程,将一个静态的使用模拟数据的应用,变成具有AngularJS特性的动态web应用.在6-8章,作者将展示如何创建一个更复杂,更真实的AngularJS应用. 1.准备项 ...

  9. C# Driver LINQ Tutorial

    1.介绍 该教程涵盖了1.8版本的C#驱动中的LINQ查询.你可能已经阅读最新的C# Driver Tutorial. 2.快速开始 首先,给程序添加下面的using声明 using MongoDB. ...

  10. PHP自定义函数格式化json数据怎么调用?

    <?php/*** Formats a JSON string for pretty printing** @param string $json The JSON to make pretty ...