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++】

 1 #include<cstdio>
 2 #include<cstring>
 3 int main(){
 4     int t, x1, y1, r1, x2, y2, r2, c_distance, r_sum, r_difference;
 5     scanf("%d", &t);
 6     while (t--){
 7         scanf("%d%d%d%d%d%d", &x1, &y1, &r1, &x2, &y2, &r2);
 8         c_distance = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
 9         r_sum = (r1 + r2)*(r1 + r2);
10         r_difference = r_sum - (r1*r2 << 2);
11         if (c_distance > r_sum) puts("4");//相离
12         else if (c_distance == r_sum) puts("3");//外切
13         else if (r_difference < c_distance &&c_distance < r_sum) puts("2");//相交
14         else if (c_distance == r_difference){
15             if (x1 ^ x2 | y1 ^ y2) puts("1");//内切
16             else puts("-1");//重合
17         }
18         else puts("0");//内含
19     }
20     return 0;
21 }

FZU 2213

转载于:https://www.cnblogs.com/Simon-X/p/5135704.html

FZU 2213 Common Tangents(公切线)相关推荐

  1. css浮动布局自适应,CSS | 自适应两栏布局方法

    html代码: 固定宽度 自适应区域 1.浮动+margin 第一种: 左侧栏固定宽度向左浮动,右侧主要内容则用margin-left留出左侧栏的宽度,默认宽度为auto,自动填满剩下的宽度. .le ...

  2. 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)

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

  3. adjacent angle_【数学几何的英语用语包括图形的名称.】作业帮

    acute angle 锐角 acute triangle 锐角三角形 adjacent angle 邻角 alternate angle 错角 alternate exterior angle 外错 ...

  4. 机器人学习--Hans Moravec在斯坦福博士论文1980年-Obstacle Avoidance and Navigation in the Real World by a Seeing Ro

    Hans Moravec,占用栅格地图的发明人. Obstacle Avoidance and Navigation in the Real World by a Seeing Robot Rover ...

  5. 最长公共子序列(LCS)问题 Longest Common Subsequence 与最长公告字串 longest common substr...

    问题描述:字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X="x0,x1,-,xm-1",序列Y=& ...

  6. PCL common中常见的基础功能函数

    这里将分享我使用PCL库的遇到的一些坑,以及总结的技巧,当然也需要各位能够多多分享,将公众号的文章或者知识星球的文章转发到朋友圈. pcl_common中主要是包含了PCL库常用的公共数据结构和方法, ...

  7. HDU 4913 Least common multiple

    /* hdu4913 Least common multiple http://acm.hdu.edu.cn/showproblem.php?pid=4913 离散化 线段树 统计逆序数思想 tips ...

  8. fzu 2150 Fire Game 【身手BFS】

    称号:fzu 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个格子扩散,问选择那两个点使得燃烧全部 ...

  9. Caffe源码中common文件分析

    Caffe源码(caffe version:09868ac , date: 2015.08.15)中的一些重要头文件如caffe.hpp.blob.hpp等或者外部调用Caffe库使用时,一般都会in ...

  10. 【js】common.jsp的使用

    通过将引入common.jsp将所有文件都需要的内容或静态资源引入,相当于一个页面,在页面被编译之前合并. 代码实现 <%@ include file = "common.jsp的相对 ...

最新文章

  1. 【spring】使用spring的环境配置及从官网获得配置文件所用代码的方法
  2. 关于ORA-01950: no privileges on tablespace 的解决
  3. 如何让你的webapp也能跳窗口搜索
  4. JSON在PHP中的基本应用
  5. 【LeetCode】3月19日打卡-Day4
  6. bootstrapV4.6.0实现标签页(改造v3.3.7)- 代码篇
  7. BZOJ2934 : [Poi1999]祭坛问题
  8. 代码块作用域内外的静态变量
  9. libgsm.a relocation R_X86_64_PC32 can not be used when making a shared object; recompile with -fPIC
  10. xml 标签带有号php,php操作xml入门之xml基本介绍及xml标签元素
  11. csdn资源下载不了问题解决 360浏览器下载不了csdn资源问题解决
  12. 自己的部分小软件合计 2000 - 2013
  13. thinkphp 短信api接口调用
  14. head标签中meta中IE=edge,chrome=1详解
  15. 微信小程序上传图片到服务器(java后台以及使用springmvc)
  16. 拿它们练Python爬虫,是在法律边缘试探吗?爬虫圈香饽饽之视频网站的评论区采集
  17. python--我的大花莽【turtle画】
  18. 2020最新整理:好用的免费/收费的第三方域名解析服务平台
  19. linux 系统qcow2镜像制作
  20. html将字符串按逗号分隔,js如何截取以逗号隔开的字符串

热门文章

  1. obj文件格式学习(自用)
  2. 2017个人工作感悟
  3. 《近匠》 | 探索一站式智能硬件开发的最佳解决方案
  4. FFMpeg 滤镜中英文对照
  5. JAVA程序设计:在圆内随机生成点(LeetCode:478)
  6. pr关键帧动画、字幕、音频
  7. 阿里云国际站怎么注册?
  8. 1371: 三位数求解
  9. Java编程题修院子_2020大学moocJava程序设计题目答案
  10. 签offer VS 签三方