2019牛客暑期多校训练营(第五场)I three points 1 计算几何

题意:问能不能将三角形放在矩形内

题解:让一个顶点在原点,另一条边卡在墙角上,分别枚举是哪条边卡在上面

虽然题目说1e-6精度以上的会被忽略。。。但是我输出.6f就是不行。。。得.10f才够

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e4;
int dcmp(double x){
	if(fabs(x)<=eps)return 0;
	else if(x>0)return 1;
	else return -1;
} 
double X1,X2,X3,Y1,Y2,Y3;
double w,h;
int check(double a,double b,double c){
	X1=0.0,Y1=0.0;
	if(dcmp(w-a)>=0)X2=a,Y2=0.0;
	else X2=w,Y2=sqrt(a*a-w*w);
	if(dcmp(Y2-h)==1)return 0;
	double d1=acos((a*a+b*b-c*c)/(2.0*a*b));
	double d2=asin(Y2/a);
	double d3=d1+d2;
	X3=b*cos(d3),Y3=b*sin(d3);
	if(dcmp(X3)>=0&&dcmp(X3-w)<=0&&dcmp(Y3)>=0&&dcmp(Y3-h)<=0)
		return 1;
	else return 0;
}
void print(double x1,double y1,double x2,double y2,double x3,double y3){
	printf("%.10f %.10f %.10f %.10f %.10f %.10f\n",x1,y1,x2,y2,x3,y3);
}
int main() 
{
	int t;
	scanf("%d",&t);
	while(t--){
		double a,b,c;
		scanf("%lf%lf",&w,&h);
		scanf("%lf%lf%lf",&a,&b,&c);
		if(check(a,b,c)) {print(X1,Y1,X2,Y2,X3,Y3);continue;}
        if(check(a,c,b)) {print(X2,Y2,X1,Y1,X3,Y3);continue;}
        if(check(b,a,c)) {print(X1,Y1,X3,Y3,X2,Y2);continue;}
        if(check(b,c,a)) {print(X2,Y2,X3,Y3,X1,Y1);continue;}
        if(check(c,a,b)) {print(X3,Y3,X1,Y1,X2,Y2);continue;}
        if(check(c,b,a)) {print(X3,Y3,X2,Y2,X1,Y1);continue;}
	}
    return 0;
}

 

你可能感兴趣的:(计算几何)