题意:现在给你一个矩形边框 一个三角形的三边长 现在问你能否把三角形放入矩阵边框中 并且输出三个点的坐标
思路:我们可以发现如果一定有解 我们就可以让一个点在左下角(0,0)处 还有一个点在矩形边上 所以我们暴力排列一下三个点 找到一个合适的三角形然后输出
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int N = 3e5+7; const int inf = 0x3f3f3f3f; const double eps = 1e-6; typedef long long ll; const ll mod = 1e7+9; int sgn(double x){ if(fabs(x) < eps)return 0; if(x < 0)return -1; else return 1; } struct Point{ double x,y; Point(){} Point(double _x,double _y){ x = _x; y = _y; } void input(){ scanf("%lf%lf",&x,&y); } void output(){ printf("%.2f %.2f ",x,y); } bool operator == (Point b)const{ return sgn(x-b.x) == 0 && sgn(y-b.y) == 0; } bool operator < (Point b)const{ return sgn(x-b.x)== 0?sgn(y-b.y)<0:x<b.x; } Point operator -(const Point &b)const{ return Point(x-b.x,y-b.y); } //叉积 double operator ^(const Point &b)const{ return x*b.y - y*b.x; } //点积 double operator *(const Point &b)const{ return x*b.x + y*b.y; } //返回长度 double len(){ return hypot(x,y);//库函数 } //返回长度的平方 double len2(){ return x*x + y*y; } //返回两点的距离 double distance(Point p){ return hypot(x-p.x,y-p.y); } Point operator +(const Point &b)const{ return Point(x+b.x,y+b.y); } Point operator *(const double &k)const{ return Point(x*k,y*k); } Point operator /(const double &k)const{ return Point(x/k,y/k); } //`计算pa 和 pb 的夹角` //`就是求这个点看a,b 所成的夹角` //`测试 LightOJ1203` double rad(Point a,Point b){ Point p = *this; return fabs(atan2( fabs((a-p)^(b-p)),(a-p)*(b-p) )); } //`化为长度为r的向量` Point trunc(double r){ double l = len(); if(!sgn(l))return *this; r /= l; return Point(x*r,y*r); } //`逆时针旋转90度` Point rotleft(){ return Point(-y,x); } //`顺时针旋转90度` Point rotright(){ return Point(y,-x); } //`绕着p点逆时针旋转angle` Point rotate(Point p,double angle){ Point v = (*this) - p; double c = cos(angle), s = sin(angle); return Point(p.x + v.x*c - v.y*s,p.y + v.x*s + v.y*c); } }; double w,h; bool check(int x,int y,int z,double a,double b,double c){ Point p[3]; p[x]=Point(0.0,0.0); double angl; if(a<=w){ p[y]=Point(a,0.0); angl=acos((a*a+b*b-c*c)/(2*a*b)); }else{ p[y]=Point(w,sqrt(a*a-w*w)); angl=acos((a*a+b*b-c*c)/(2*a*b))+acos(w/a); } p[z]=Point(b*cos(angl),b*sin(angl)); if(sgn(h-p[z].y)!=-1&&sgn(w-p[z].x)!=-1&&sgn(p[z].x)!=-1&&sgn(p[z].y)!=-1){ printf("%.12f %.12f %.12f %.12f %.12f %.12f " ,p[0].x,p[0].y,p[1].x,p[1].y,p[2].x,p[2].y); return true; } return false; } int main(){ // ios::sync_with_stdio(false); // cin.tie(0); cout.tie(0); int t; scanf("%d",&t); while(t--){ scanf("%lf%lf",&w,&h); double a,b,c; scanf("%lf%lf%lf",&a,&b,&c); double g[5][5]={0}; g[0][1]=a; g[0][2]=b; g[1][2]=c; g[1][0]=a; g[2][0]=b; g[2][1]=c; bool f=1; for(int i=0;i<3&&f;i++) for(int j=0;j<3&&f;j++){ if(i==j) continue; for(int k=0;k<3&&f;k++){ if(k==i||k==j) continue; if(check(i,j,k,g[i][j],g[i][k],g[j][k])) f=0; } } } }