Problem 2213 Common Tangents

Accept: 7    Submit: 8
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem 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.

 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.

 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.

 Sample Input

3
10 10 5 20 20 5
10 10 10 20 20 10
10 10 5 20 10 5

 Sample Output

4
2
3

 Source

第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)

 
 
题目大意:给你两个圆的圆心和半径,问你一共有多少条切线。
 
解题思路:讨论圆心距跟半径和与差的关系。
 
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
struct Circle{
double x,y,r;
};
int getTangents(Circle A,Circle B){
int cnt = 0;
if(A.r < B.r){ swap(A,B); } //固定A为大圆
int d2 = (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y); //圆心距的平方
int rdiff = A.r - B.r; //半径差
int rsum = A.r + B.r; //半径和
if(d2 < rdiff*rdiff) return 0; //内含
double base = atan2(B.y-A.y,B.x-A.x); //求出两个圆心所在直线与x轴正方向的夹角
if(d2 == 0 && A.r == B.r) return -1; //两个圆相等,无数条切线
if(d2 == rdiff*rdiff){ //内切,一条切线
cnt++;
return 1;
}
double ang = acos((A.r-B.r)/sqrt(d2));
//两条外公切线
cnt++; cnt++;
if(d2 == rsum*rsum){ //外切,一条内公切线
cnt++;
}else if(d2 > rsum*rsum){ //相离,两条内公切线
cnt++; cnt++;
}
return cnt;
}
int main(){
int T;
Circle r1, r2;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf%lf%lf",&r1.x,&r1.y,&r1.r,&r2.x,&r2.y,&r2.r);
int ans = getTangents(r1,r2);
printf("%d\n",ans);
}
return 0;
}

  

FZU 2213——Common Tangents——————【两个圆的切线个数】的更多相关文章

  1. FZU 2213 Common Tangents(公切线)

    Description 题目描述 Two different circles can have at most four common tangents. The picture below is a ...

  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. 实验12:Problem D: 判断两个圆之间的关系

    Home Web Board ProblemSet Standing Status Statistics   Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...

  6. POJ 2546 Circular Area(两个圆相交的面积)

    题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...

  7. java求两个圆相交坐标

    最近由于项目需要,根据两个圆函数求出相交的坐标.实现代码如下,另感谢两圆求交点算法实现Java代码,虽然他所贡献的代码中存在问题,但仍有借鉴意义. 1.两个圆相交的数学求法 在中学数学中我们知道,一个 ...

  8. C++ 判断两个圆是否有交集

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <math.h> #include <easyx.h ...

  9. poj1375Intervals(点到圆的切线)

    链接 貌似这样的叫解析几何 重点如何求得过光源到圆的切线与地板的交点x坐标,可以通过角度及距离来算,如图, 根据距离和半径可以求得角度a.b.r,自然也可以求得d1,d2. 至于方向问题,在求r得时候 ...

随机推荐

  1. 变量声明和定义的关系------c++ primer

    为了允许把程序分成多个逻辑部分来编写,c++语言支持分离式编译机制 为了支持分离式编译,c++语言把声明和定义区分开来.声明(declaration)使得名字为程序所知,一个文件如果想使用别处定义的名 ...

  2. Nginx conf基本配置

    #定义Nginx运行的用户和用户组 user www www;   #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8;   #全局错误日志定义类型,[ debu ...

  3. day08.3-apache网页服务

    1. 安装软件:yum   install   httpd   -y 2. 查看配置文件:vim   /etc/httpd/conf/httpd.cof,其中,"Listen   80&qu ...

  4. javascript点击变绿色再点击变红色

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 《Andrew Ng深度学习》笔记2

    神经网络基础 1.图计算 计算时有两种方法:正向传播和反向传播.正向传播是从底层到顶层的计算过程,逐步推出所求公式.反向传播是从顶层到底层,从已知的式子求出因变量的影响关系. 在这里用到的反向传播算法 ...

  6. ARKit的使用

    //创建场景 let scene = SCNScene() /* //1.几何 let box = SCNBox.init(width: 0.1, height: 0.1, length: 0.1, ...

  7. Hibernate学习笔记(四)—— 表与表的关系

    一.一对多|多对一 1.1 关系表达 1.1.1 表中的表达 建表原则:在多的一方创建外键指向一的一方的主键. 1.1.2 实体中的表达 [客户实体] public class Customer { ...

  8. C++_代码重用1-总览

    C++的主要目的是促进代码重用. 公有继承是实现这一目标的机制之一: 本身是另一个类的成员,这种方法称为包含.组合.层次化. 另一种方法是使用私有.保护继承. 通常包含.私有继承和保护继承用于实现ha ...

  9. SGU - 495 概率DP

    题意:n个带礼物的盒子和m个人,每个人拿一个盒子并放回,如果里面有礼物就拿走(盒子还是留下),问m个人带走礼物的期望 #include<iostream> #include<algo ...

  10. flex布局在ios8上的兼容性问题

    最近在做项目时,使用到了flex布局.其他ios版本都还好,唯独在ios8上遇到了flex布局没起作用的问题.后来经过研究才发现,safari使用的是webkit内核,在ios8上需要单独加一下兼容才 ...