ZOJ 1199 Point of Intersection
2017-04-21 17:46
447 查看
Given two circles on the same plane which are centered at (x1,y1) and (x2,y2) ,with radiuses r1 and r2, respectively.We can see that they have two common tangent lines in most of the cases.Now you are asked to write a programme to calculate the point of
intersection of the two tangents if there exists one. ( See Figure 1 )
Figure. 1 Point of intersection
Input
The input data consists of the information of several figures.The first line of the input contains the number of figures.
Each figure is described by two lines of data.Each line contains 3 integers constituting the coordinates of the center (x, y) and the radius r (>0) of a circle.
Output
For each figure, you are supposed to output the coordinates (x, y) of the point of intersection if it exists.The x and y must be rounded to two decimal places and be separated by one space.If there is
no such point exists simply output "Impossible."
Sample Input
Output for the Sample Input
Notice
The common tangent lines like the following figure don't take into account;
无聊的几何题,推公式就行了。
#include<map>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
long long a1,a2,b1,b2,r1,r2;
int main()
{
int _;
scanf("%d",&_);
while(_--)
{
scanf("%lld%lld%lld",&a1,&b1,&r1);
scanf("%lld%lld%lld",&a2,&b2,&r2);
if(r1==r2||(r1-r2)*(r1-r2)>=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)) puts("Impossible.");
else
{
if(r1<r2)
{
swap(a1,a2);
swap(b1,b2);
swap(r1,r2);
}
double d1=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2);
d1=sqrt(d1);
double d=d1*r2/(r1-r2);
double k1=1.0*(b2-b1);
double k2=1.0*(a2-a1);
printf("%.2lf %.2lf\n",a2+d*k2/sqrt(k1*k1+k2*k2),b2+d*k1/sqrt(k1*k1+k2*k2));
}
}
return 0;
}
intersection of the two tangents if there exists one. ( See Figure 1 )
Figure. 1 Point of intersection
Input
The input data consists of the information of several figures.The first line of the input contains the number of figures.
Each figure is described by two lines of data.Each line contains 3 integers constituting the coordinates of the center (x, y) and the radius r (>0) of a circle.
Output
For each figure, you are supposed to output the coordinates (x, y) of the point of intersection if it exists.The x and y must be rounded to two decimal places and be separated by one space.If there is
no such point exists simply output "Impossible."
Sample Input
2 0 0 10 0 0 5 0 0 10 10 0 1
Output for the Sample Input
Impossible. 11.11 0.00
Notice
The common tangent lines like the following figure don't take into account;
无聊的几何题,推公式就行了。
#include<map>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
long long a1,a2,b1,b2,r1,r2;
int main()
{
int _;
scanf("%d",&_);
while(_--)
{
scanf("%lld%lld%lld",&a1,&b1,&r1);
scanf("%lld%lld%lld",&a2,&b2,&r2);
if(r1==r2||(r1-r2)*(r1-r2)>=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)) puts("Impossible.");
else
{
if(r1<r2)
{
swap(a1,a2);
swap(b1,b2);
swap(r1,r2);
}
double d1=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2);
d1=sqrt(d1);
double d=d1*r2/(r1-r2);
double k1=1.0*(b2-b1);
double k2=1.0*(a2-a1);
printf("%.2lf %.2lf\n",a2+d*k2/sqrt(k1*k1+k2*k2),b2+d*k1/sqrt(k1*k1+k2*k2));
}
}
return 0;
}
相关文章推荐
- zoj 1199 Point of Intersection
- ZOJ 1199 Point of Intersection(平面几何)
- ZOJ 1199 Point of Intersection
- zoj1199-Point of Intersection
- Data Structure Linked List: Write a function to get the intersection point of two Linked Lists.
- zoj 3198 Intersection of Two Sets
- ZOJ 3198 Intersection of Two Sets
- ZOJ1199-Point of Intersection
- Point of Intersection
- Find the first intersection of two lists (if the two list are merged at some point)
- ZOJ 3198 Intersection of Two Sets
- ZOJ 3198 Intersection of Two Sets
- ZOJ 3198 Intersection of Two Sets
- ZOJ1199Point of Intersection【公式推导】
- ZOJ 2110 Tempter of the Bone
- zoj 2822 Sum of Different Primes (01背包)
- Intersection of internal tables
- Leetcode-349 Intersection of Two Arrays
- UVA 10790 How Many Points of Intersection? 简单数学题
- Intersection of Two Arrays(两数组的交叉元素)