I three points 1(计算几何)
题意
给一个三角形的三条边,问这个三角形能否放进一个矩形内。
思路
其实想起来很简单,就是把一个点放在原点然后一条边紧靠在矩形上,这样就确定两个点,然后再算出另一个点坐标,看是否合法就好了,每个点每条边都尝试一下,总共6种情况。
现场做的时候想的是把最长边靠在矩形最长边就可以了,但实际上是错误的,必须每种情况都尝试一下才能确定。
然后被这个输出也恶心坏了,非得要x,y,z的顺序输出,对应边还不是a,b,c。然后改这个顺序改半天。。。。。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#define lson node<<1
#define rson node<<1|1
using namespace std;
typedef long long ll;
const ll inf=(ll)(2e5)*(ll)(1e9)+900;
const int maxn = 1e4;
struct point{
double x,y;
point(){}
point(double x,double y):x(x),y(y){}
}ans[5];
double eps=1e-10;
double w,h;
bool slove(double a,double b,double c,int A,int B,int C)
{
ans[A]=point(0.0,0.0);
double angle=acos((b*b+c*c-a*a)/(2.0*b*c));
if(c<=w)
{
ans[B]=point(c,0.0);
}
else
{
double hi=sqrt(c*c-w*w);
ans[B]=point(w,hi);
angle+=acos(w/c);
}
ans[C]=point(b*cos(angle),b*sin(angle));
if(0.0-eps<=ans[C].x&&ans[C].x<=w+eps&&0.0-eps<=ans[C].y&&ans[C].y<=h+eps)
{
printf("%.12f %.12f %.12f %.12f %.12f %.12f\n",ans[1].x,ans[1].y,ans[2].x,ans[2].y,ans[3].x,ans[3].y);
return true;
}
return false;
}
int main(){
int t;
cin>>t;
double a,b,c;
while(t--)
{
cin>>w>>h>>a>>b>>c;
if(slove(a,b,c,3,2,1))
continue;
if(slove(a,c,b,3,1,2))
continue;
if(slove(b,a,c,2,3,1))
continue;
if(slove(b,c,a,2,1,3))
continue;
if(slove(c,a,b,1,3,2))
continue;
if(slove(c,b,a,1,2,3))
continue;
}
}