链接:https://ac.nowcoder.com/acm/contest/885/I
题意:T组样例,给你w、h、a、b、c。让你按顺序输出3个坐标X、Y、Z,其中X、Y的距离是a,X、Z的距离是b,Y、Z的距离是c。并且这3个点x坐标要在[0,w]之内,y坐标要在[0,h]之内。保证一定存在这样的3个点。
思路:最优解就是把两个点固定在边上,其中一个固定在原点,另一个根据距离固定在边。这样的话,留出的空间最大,也最有可能放下第3个点。一共6种情况,挨个试一下,肯定能找到一个。注意,由于浮点数存在误差,判断时,超过一点可以忽略。注意要按顺序输出,MD改了一上午。。。。。。。。。。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const double eps = 1e-10;
double w,h,a,b,c;
struct point
{
double x,y;
point(){}
point(double x,double y):x(x),y(y){}
}ps[4];
bool judge(double a,double b,double c,int A,int B,int C)
{
ps[A]=point(0.0,0.0);
double angle=acos((a*a+b*b-c*c)/(2.0*a*b));
if(a<=w) ps[C]=point(a,0.0);
else ps[C]=point(w,sqrt(a*a-w*w)),angle+=acos(w/a);
ps[B]=point(b*cos(angle),b*sin(angle));
//误差处理
if((0.0-eps<=ps[B].x&&ps[B].x<=w+eps)&&(0.0-eps<=ps[B].y&&ps[B].y<=h+eps))
{
printf("%.12f %.12f %.12f %.12f %.12f %.12f\n",ps[1].x,ps[1].y,ps[2].x,ps[2].y,ps[3].x,ps[3].y);
return 1;
}
return 0;
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf",&w,&h,&a,&b,&c);
if(judge(a,b,c,1,3,2)) continue;
if(judge(a,c,b,2,3,1)) continue;
if(judge(b,a,c,1,2,3)) continue;
if(judge(b,c,a,3,2,1)) continue;
if(judge(c,a,b,2,1,3)) continue;
if(judge(c,b,a,3,1,2)) continue;
}
return 0;
}