现在的位置: 首页 > 综合 > 正文

UVA – 12301-An Angular Puzzle

2019年11月07日 ⁄ 综合 ⁄ 共 969字 ⁄ 字号 评论关闭

给出如图三角形里的五个角度,求出x

我的做法:

直接写出表达式解

我的代码:

#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double pi=acos(-1.0);
struct dot
{
	double x,y;
	dot(){}
	dot(double a,double b){x=a,y=b;}
	friend dot operator -(dot a,dot b){return dot(a.x-b.x,a.y-b.y);}
	friend double operator /(dot a,dot b){return a.x*b.x+a.y*b.y;}
};
double dis(dot a,dot b)
{
	return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
double cang(dot a,dot b)
{
	return acos(a/b/dis(a,dot(0,0))/dis(b,dot(0,0)));
}
double cg1(double a)
{
	return a/pi*180;
}
double cg2(double a)
{
	return a/180*pi;
}
int main()
{
	dot f,g;
	double a,b,c,d,e,k[10],ans;
	while(cin>>a>>b>>c>>d>>e)
	{
		if(a+b+c+d+e==0)
			break;
		if(a+b+c+d+e>180.0)
			printf("Impossible\n");
		else
		{
			a=cg2(a);b=cg2(b);c=cg2(c);d=cg2(d);e=cg2(e);
			k[1]=-tan(d+e);
			k[2]=tan(c);
			k[3]=tan(b+c);
			k[4]=-tan(e);
			f.x=k[1]/(k[1]-k[2]);
			f.y=k[2]*f.x;
			g.x=k[4]/(k[4]-k[3]);
			g.y=k[3]*g.x;
			ans=cg1(cang(f-g,f));
			printf("%.2lf\n",ans);
		}
	}
}

抱歉!评论已关闭.