UVA - 10674-Tangents

本文介绍了一种通过模拟方法来求解两个圆之间的所有公切线的算法实现。该算法能正确处理各种情况,包括没有公切线、有一条公切线以及有多条公切线的情形,并给出了完整的C++代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



题意:给出两个圆,求它们的公切线,并依照一定格式输出


做法:模拟


代码:


#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

Download as PDF

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

Root :: Prominent Problemsetters :: Shahriar Manzoor
内容概要:该PPT详细介绍了企业架构设计的方法论,涵盖业务架构、数据架构、应用架构和技术架构四大核心模块。首先分析了企业架构现状,包括业务、数据、应用和技术四大架构的内容和关系,明确了企业架构设计的重要性。接着,阐述了新版企业架构总体框架(CSG-EAF 2.0)的形成过程,强调其融合了传统架构设计(TOGAF)和领域驱动设计(DDD)的优势,以适应数字化转型需求。业务架构部分通过梳理企业级和专业级价值流,细化业务能力、流程和对象,确保业务战略的有效落地。数据架构部分则遵循五大原则,确保数据的准确、一致和高效使用。应用架构方面,提出了分层解耦和服务化的设计原则,以提高灵活性和响应速度。最后,技术架构部分围绕技术框架、组件、平台和部署节点进行了详细设计,确保技术架构的稳定性和扩展性。 适合人群:适用于具有一定企业架构设计经验的IT架构师、项目经理和业务分析师,特别是那些希望深入了解如何将企业架构设计与数字化转型相结合的专业人士。 使用场景及目标:①帮助企业和组织梳理业务流程,优化业务能力,实现战略目标;②指导数据管理和应用开发,确保数据的一致性和应用的高效性;③为技术选型和系统部署提供科学依据,确保技术架构的稳定性和扩展性。 阅读建议:此资源内容详尽,涵盖企业架构设计的各个方面。建议读者在学习过程中,结合实际案例进行理解和实践,重点关注各架构模块之间的关联和协同,以便更好地应用于实际工作中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值