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模块 ...
随机推荐
- codereview
http://www.cnblogs.com/wenhx/p/How-We-Code-Review.htmlhttp://www.cnblogs.com/mindwind/p/5639008.html ...
- css中的选择器
选择器 说明 * 通用元素选择器,匹配任何元素 E 标签选择器,匹配所有使用E标签(所有HTML元素)的元 ...
- html5 图片热点area,map的用法
今天看了一个html5在图片上面创建热点的标签,所谓图片热点就是给你一张图片然后你可以设置点击图片不同的位置进入不同的链接!如果下面是一张图片的话,里面在长方形.圆形.三角形区域都可以进入其他网页! ...
- linux设备驱动归纳总结(八):4.总线热插拔【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-110774.html linux设备驱动归纳总结(八):4.总线热插拔 xxxxxxxxxxxxxxx ...
- 161014、Comet4J介绍及使用(即时推送)
简介 Comet4J是一个微型的即时推送框架(类似于goeasy),它分为服务端与客户端两部分,你只要将服务器端(JAR文件,目前仅支持Tomcat6.7)放入WEB-INF\lib,客户端(Java ...
- ubuntu安装最新版本的node.js
下面的方法适用于最新版本的Ubuntu.Ubuntu 12.04 LTS.Ubuntu 12.10.Ubuntu 13.04等版本.它可以帮助开发者在Ubuntu上安装Node.js,无需从头编译安装 ...
- powershell: 生成随机字符串
ASCII范围内的 获取6个随机字符(字母和数字) 48到57是数字0-9,powershell的范围操作符是..,和Perl 5的一样, 所以 48..57就是指(48 49 50 51 52 53 ...
- PHP安全函数phpinfo()
phpinfo() 功能描述:输出 PHP 环境信息以及相关的模块.WEB 环境等信息. 危险等级:中 passthru() 功能描述:允许执行一个外部程序并回显输出,类似于 exec(). 危险等级 ...
- PHP正则表达式的使用
1. 正则表达式的主要作用是:分割.匹配.查找.替换2. 正则表达式中包括的元素:原子(普通字符:a-z A-Z 0-9 .原子表.转义字符),元字符(有特殊功能的字符),模式修正符(系统内置部分字符 ...
- C#:WiFi
写的一个简单启动关闭WiFi的类:具体如下 using System; using System.Collections.Generic; using System.Text; using Syste ...