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

链接: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;	
} 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值