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模块 ...
随机推荐
- mysql字符串相关
使用MySQL,我们很多时候都会出现需要截取字符串的情况,所以关于字符串的截取的方式有必要记录下去. MySQL截取字符串的函数有: left(str, length):从左边开始截取,length是 ...
- sql server 2012 自定义聚合函数(MAX_O3_8HOUR_ND) 计算最大的臭氧8小时滑动平均值
采用c#开发dll,并添加到sql server 中. 具体代码,可以用visual studio的向导生成模板. using System; using System.Collections; us ...
- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on ...
- Houdini Krakatoa Render Plugin
HDK真实个混蛋,都懒得写个解释.凭着函数英文意思猜测.. plugin sample video: 在极其残忍的开发环境,"Particle Voxel Render" 产生了( ...
- java 面试每日一题6
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5 ...
- ScheduledExecutorService定时周期执行指定的任务
示例代码 package com.effective.common.concurrent.execute; import java.text.DateFormat; import java.text. ...
- AndroidManifest.xml 详解
第1部分 标签库+包路径+版本控制 <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...
- openmp在图像处理上面的运用
// openmptest的测试程序 // #include "stdafx.h" void Test(int n){ for (int i=0;i<1000 ...
- C#中通过Selenium定位<a>标签的问题
刚才在QQ群里看到有人提问,如何实现退出百度登录问题.那么之所以会有这个问题,主要是因为这个元素,如下图所示,是无法直接定位到的: 经过研究发现,要想定位到这种元素,拢共分两步: 第一步,把鼠标移到能 ...
- MSSQL删除字段时出现 服务器: 消息 5074,级别 16,状态 1,行 1 的解决办法
有的朋友在做用户维护字段的界面时,肯定发现一个问题,当用脚本:ALTER TABLE 表名 DROP COLUMN 字段名进行删除字段的操作时,会出现“服务器: 消息 5074,级别 16,状态 1, ...