UVA - 10674-Tangents
题意:给出两个圆,求它们的公切线,并依照一定格式输出
做法:模拟
代码:
#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double eps=2e-5;
const double pi=acos(-1.0);
int dcmp(double x){return fabs(x)<eps? 0:x<0?-1:1;}
struct dot
{
double x,y;
dot(){}
dot(double a,double b){x=a;y=b;}
dot operator +(dot a){return dot(x+a.x,y+a.y);}
dot operator -(dot a){return dot(x-a.x,y-a.y);}
dot operator *(double a){return dot(x*a,y*a);}
double operator *(dot a){return x*a.y-y*a.x;}
dot operator /(double a){return dot(x/a,y/a);}
double operator /(dot a){return x*a.x+y*a.y;}
bool operator ==(dot a){return x==a.x&&y==a.y;}
void in(){scanf("%f%f",&x,&y);}
void out(){printf("%f %f\n",x,y);}
dot norv(){return dot(-y,x);}
dot univ(){double a=mod();return dot(x/a,y/a);}
dot ro(double a){return dot(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a));}
double mod(){return sqrt(x*x+y*y);}
double dis(dot a){return sqrt(pow(x-a.x,2)+pow(y-a.y,2));}
};
typedef pair<dot,dot> LL;
LL ans[10];
bool operator <(LL a,LL b)
{
return dcmp(a.first.x-b.first.x)!=0?dcmp(a.first.x-b.first.x)<0:
dcmp(a.first.y-b.first.y)<0;
}
int work(dot a,double r1,dot b,double r2)
{
int cnt;
double ang;
if(dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0&&dcmp(r1-r2)==0)
return -1;
if(dcmp(a.dis(b)+min(r1,r2)-max(r1,r2))<0)
return 0;
if(dcmp(a.dis(b)+min(r1,r2)-max(r1,r2))==0)
{
if(dcmp(r1-r2)>0)
ans[0].first=ans[0].second=a+(b-a).univ()*r1;
else
ans[0].first=ans[0].second=b+(a-b).univ()*r2;
return 1;
}
ang=acos((r1-r2)/a.dis(b));
ans[0].first=a+(b-a).ro(ang).univ()*r1;
ans[1].first=a+(b-a).ro(-ang).univ()*r1;
ang=pi-ang;
ans[0].second=b+(a-b).ro(-ang).univ()*r2;
ans[1].second=b+(a-b).ro(ang).univ()*r2;
cnt=2;
if(dcmp(a.dis(b)-r1-r2)==0)
{
ans[2].first=ans[2].second=a+(b-a).univ()*r1;
cnt=3;
}
if(dcmp(a.dis(b)-r1-r2)>0)
{
ang=acos((r1+r2)/a.dis(b));
ans[2].first=a+(b-a).ro(ang).univ()*r1;
ans[3].first=a+(b-a).ro(-ang).univ()*r1;
ans[2].second=b+(a-b).ro(ang).univ()*r2;
ans[3].second=b+(a-b).ro(-ang).univ()*r2;
cnt=4;
}
sort(ans,ans+cnt);
return cnt;
}
int main()
{
int i,cnt;
dot a,b;
double r1,r2;
while(cin>>a.x>>a.y>>r1>>b.x>>b.y>>r2)
{
if(a.x==0&&a.y==0&&r1==0&&b.x==0&&b.y==0&&r2==0)
return 0;
cnt=work(a,r1,b,r2);
cout<<cnt<<endl;
for(i=0;i<cnt;i++)
printf("%.5f %.5f %.5f %.5f %.5f\n",ans[i].first.x,ans[i].first.y,
ans[i].second.x,ans[i].second.y,ans[i].first.dis(ans[i].second));
}
}
Description
Problem B
Tangents
Input: standard input
Output: standard output
Time Limit: 2 seconds
You can see in the pictures below that two different circles can have at most four common tangents. Given the center and radius of two circles your job is to find the length of their common tangents and also the points where they touch the two circles.

Input
The input file contains several lines of inputs.
Each 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.
Input is terminated by a line containing six zeroes.
Output
For each line of input you should produce one of more lines of output. The description of this output is given below.
First line of the output for each line of input contains an integer
n, which denotes the number of different tangents between the two circles. If there is infinite number of tangents between the two circles then the value of
n should be –1. If n is positive then next
n lines contains the description of each tangent. The description of the tangent contains five floating-point numbers
Sx, Sy, Tx,
Ty, L in a single line. Here
(Sx, Sy) is the point at which the tangent touches the first circle and
(Tx, Ty) is the point where the tangent touches the second circle and
L is the length of the tangent. All the floating-point numbers have five digits after the decimal point. Errors less than
2*10-5 will be ignored. The tangents should be printed in ascending order of
Sx and in case of a tie they should be printed in ascending order of
Sy.
Sample Input
Output for Sample Input
|
10 10 5 20 20 5 10 10 10 20 20 10 10 10 5 20 10 5 0 0 0 0 0 0 |
4 6.46447 13.53553 16.46447 23.53553 14.14214 10.00000 15.00000 20.00000 15.00000 10.00000 13.53553 6.46447 23.53553 16.46447 14.14214 15.00000 10.00000 15.00000 20.00000 10.00000 2 2.92893 17.07107 12.92893 27.07107 14.14214 17.07107 2.92893 27.07107 12.92893 14.14214 3 10.00000 5.00000 20.00000 5.00000 10.00000 10.00000 15.00000 20.00000 15.00000 10.00000 15.00000 10.00000 15.00000 10.00000 0.00000
|
Problem setter: Shahriar Manzoor. Member of Elite Problem Setters’ Panel
Special Thanks: Derek Kisman, Member of Elite Problem Setters’ Panel
Input
Output
Sample Input
Sample Output
Hint
Source
UVA - 10674-Tangents的更多相关文章
- ●UVA 10674 Tangents
题链: https://vjudge.net/problem/UVA-10674 题解: 计算几何,求两个圆的公切线. <算法竞赛入门经典——训练指南>P266,讲得很清楚的. 大致是分为 ...
- UVa 10674 (求两圆公切线) Tangents
题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
随机推荐
- CF402E Strictly Positive Matrix(矩阵,强联通分量)
题意 给定一个 n∗n 的矩阵 A,每个元素都非负判断是否存在一个整数 k 使得 A^k 的所有元素 >0 n≤2000(矩阵中[i][i]保证为1) 题解 考虑矩阵$A*A$的意义 ,设得到的 ...
- cookie 实现记住用户名演示 通过代码迅速理解cookie
// 登录页 可直接 tomcat部署 测试 1 package com.itheima.login; import java.io.IOException; import java.io.Print ...
- Python组织文件 实践:查找大文件、 用Mb、kb显示文件尺寸 、计算程序运行时间
这个小程序很简单原本没有记录下来的必要,但在编写过程中又让我学到了一些新的知识,并且遇到了一些不能解决的问题,然后,然后就很有必要记录一下. 这个程序的关键是获取文件大小,本来用 os.path.ge ...
- 读 Paxos 到 ZooKeeper ¥ 50大洋
一 初识 ZooKeeper 高效且可靠的分布式协调服务.解决分布式一致性问题 统一命名服务.配置管理服务.分布式锁服务. 使用: 比如配 ...
- Spring-boot非Mock测试MVC,调试启动tomcat容器
平常我们在使用spring-boot去debug一个web应用时,通常会使用MockMvc. 如下配置: @RunWith(value = SpringRunner.class) @SpringBoo ...
- [Python] numpy fillna() for Dataframe
In the store marketing, for many reason, one stock's data can be incomplete: We can use 'forward fil ...
- 【JavaScript】分秒倒计时器
一.基本目标 在JavaScript设计一个分秒倒计时器,一旦时间完毕使button变成不可点击状态 详细效果例如以下图.为了说明问题.调成每50毫秒也就是每0.05跳一次表, 真正使用的时候,把wi ...
- SharePoint创建Alternate Access Mapping (AAM)备用訪问映射
SharePoint创建Alternate Access Mapping (AAM)备用訪问映射 SharePoint的仓库是SQL Server中的内容数据库.这些数据库储存着组织全 ...
- Visual Code中的智能提示
https://code.visualstudio.com/docs/editor/intellisense C# https://marketplace.visualstudio.com/items ...
- 13. Intellij IDEA调试功能使用总结
转自:https://www.cnblogs.com/Bowu/p/4026117.html 这段时间一直在使用Intellij IDEA, 今天把调试区工具的使用方法记录于此. 先编译好要调试的程序 ...