您的位置:首页 > 其它

2015多校第一场1008 hdu 5295 Unstable

2015-07-29 20:45 483 查看
题意:给定AB,BC,CD,DA距离,已经AB的中点E,CD的中点F的距离EF。给出一个合法的A,B,C,D坐标。

做法:和题解一样。首先其中B,C两个点的坐标可以自己定,不妨设C为(0,0),B为(BC,0),然后从A点过F作A'令AF=A'F,由于对顶三角形的原因,A'C=AD。由于相似三角形的原因A'B=2*EF,已知两点坐标和三边长,可以求出A'的坐标。然后作点G,令向量GB=向量A'C,这样就可以连接GC,GD,GC已知。由于BG与AD此时是两条平行且相等的边,所以四边形ADGB构成了一个平行四边形,所以GD=AB。所以可以通过GC,GD,CD已经点G,C的坐标求出点D坐标。那么A的坐标就很容易求了。

PS:上面两个求三角形的过程中,要考虑不是三角形的情况。

PSS:标程的求圆交点姿势比我不知道高到哪里去了。于是就学习了。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define eps 1e-6
int sgn(double x){
if(fabs(x) <= eps) return 0;
return x > 0 ? 1 : -1;
}
struct Point{
double x,y;
Point(){}
Point(const double  &x,const double  &y):x(x),y(y){}
double sqrlen()
{
return x*x+y*y;
}
double len()
{
return sqrt(sqrlen());
}
void print()
{
printf("%.6lf %.6lf\n",x,y);
}
};
Point operator +(Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
Point operator -(Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
struct Circle{
Point o;
double r;
Circle(){}
Circle(const Point &o,const double &r):o(o),r(r){}
};
bool zero(double x)
{
if(fabs(x)<=eps)return true;
return false;
}
bool operator == (Circle a,Circle b)
{
Point c=a.o-b.o;
if(zero(c.x)&&zero(c.y)&&zero(a.r-b.r))return true;
return false;
}

void c2point(Circle c1,Circle c2,Point &rp1,Point &rp2){
if(c1 == c2){
rp1 = c1.o + Point(0,c1.r);
rp2 = c1.o - Point(0,c1.r);
return;
}
Point p1 = c1.o , p2 = c2.o;
double r1 = c1.r , r2 = c2.r;
double a = p2.x - p1.x , b = p2.y - p1.y , r = (a*a + b*b + r1*r1 - r2*r2) / 2;
double tmp;
if(a == 0 && b != 0){
rp1.y = rp2.y = r / b;
tmp = r1 * r1 - rp1.y * rp1.y;
if(sgn(tmp)<=0) tmp = 0;
rp1.x = sqrt(tmp);
rp2.x = -rp1.x;
}
else if(a != 0 && b == 0){
rp1.x = rp2.x = r / a;
tmp = r1 * r1 - rp1.x * rp1.x;
if(sgn(tmp)<=0) tmp = 0;
rp1.y = sqrt(tmp);
rp2.y = -rp1.y;
}
else if(a != 0 && b != 0){
double delta = b*b*r*r - (a*a + b*b) * (r*r - r1*r1*a*a);
if(sgn(delta)<=0) delta = 0;
rp1.y = (b*r + sqrt(delta)) / (a*a + b*b);
rp2.y = (b*r - sqrt(delta)) / (a*a + b*b);
rp1.x = (r - b*rp1.y) / a;
rp2.x = (r - b*rp2.y) / a;
}
rp1.x += p1.x , rp1.y += p1.y;
rp1.x += p1.x , rp2.y += p1.y;
}
Point A,B,C,D,_A;
double AB , BC , CD , DA , EF;
int main()
{
//	freopen("1008.in","r",stdin);
//	freopen("myout.out","w",stdout);
int T,cas=0;
scanf("%d",&T);
while(T--)
{
cas++;
scanf("%lf%lf%lf%lf%lf",&AB,&BC,&CD,&DA,&EF);
B=Point(BC,0);
C=Point(0,0);
Point nouse;
Circle BO,CO;
BO=Circle(B,2*EF);
CO=Circle(C,DA);
c2point(CO,BO,_A,nouse);
Point G=_A+(B-C);
Circle GO;
CO=Circle(C,CD);
GO=Circle(G,AB);
c2point(CO,GO,D,nouse);
A=D+(C-_A);
printf("Case #%d:\n",cas);
A.print();
B.print();
C.print();
D.print();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: