FZU 2213 Common Tangents(公切线)
|
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(公切线)的更多相关文章
- FZU 2213——Common Tangents——————【两个圆的切线个数】
Problem 2213 Common Tangents Accept: 7 Submit: 8Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- 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 ...
- 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)
from:piaocoder Common Tangents(两圆之间的公公切线) 题目链接: http://acm.fzu.edu.cn/problem.php?pid=2213 解题思路: 告诉你 ...
- UVA - 10674-Tangents
题意:给出两个圆,求它们的公切线,并依照一定格式输出 做法:模拟 代码: #include<iostream> #include<map> #include<str ...
- Circles and Pi
Circles and Pi Introduction id: intro-1 For as long as human beings exist, we have looked to the sky ...
- UVa 10674 (求两圆公切线) Tangents
题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...
- Socket聊天程序——Common
写在前面: 上一篇记录了Socket聊天程序的客户端设计,为了记录的完整性,这里还是将Socket聊天的最后一个模块--Common模块记录一下.Common的设计如下: 功能说明: Common模块 ...
随机推荐
- 五分钟打造自己的sql性能分析工具
1.首先要有一个trace文件 2. 打开trace文件 3. 另存为跟踪表 4.登录你要保存到的目标sqlserver服务器 5. 选择要保存的数据库和表名称 6. 保存完成(左下角出现进度直到显示 ...
- 给MD5加上salt随机盐值加密算法实现密码安全的php实现
给MD5加上salt随机盐值加密算法实现密码安全的php实现 如果直接对密码进行散列,那么黑客可以对通过获得这个密码散列值,然后通过查散列值字典(例如MD5密码破解网站),得到某用户的密码.加上sal ...
- Delphi的DateToStr StrToDate格式灵活用法
Delphi的DateToStr StrToDate格式灵活用法 2008-04-09 10:19 procedure TForm1.Button1Click(Sender: TObject);var ...
- Understanding the RelationshipType Enumeration [AX 2012]
Understanding the RelationshipType Enumeration [AX 2012] 3 out of 3 rated this helpful - Rate this t ...
- Temporary Tables and the TableType Property [AX 2012]
Temporary Tables and the TableType Property [AX 2012] 1 out of 1 rated this helpful - Rate this topi ...
- PHP自定义函数格式化json数据怎么调用?
<?php/*** Formats a JSON string for pretty printing** @param string $json The JSON to make pretty ...
- 深入浅出Java垃圾回收机制
JVM学习笔记 JVM内存管理和JVM垃圾回收 JVM内存组成结构 JVM内存结构由堆.栈.本地方法栈.方法区等部分组成,结构图如下所示: 1)堆 所有通过new创建的对象的内存都在堆中分配,其大小可 ...
- Android动画的使用总结
1.补间动画(透明渐变.平移.旋转.缩放.组合) 方法一:通过xml文件设置 1-1:创建:res/anim 1-2:java代码写调用 Animation a = AnimationUtils.lo ...
- SQL Server 索引和表体系结构(一)
转自:http://www.cnblogs.com/chenmh/p/3780221.html 聚集索引 概述 关于索引和表体系结构的概念一直都是讨论比较多的话题,其中表的各种存储形式是讨论的重点,在 ...
- 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) B
链接:http://codeforces.com/gym/101116 学弟做的,以后再补 #include <iostream> #include <stdio.h> #in ...