码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 12301-An Angular Puzzle

时间:2014-09-12 20:48:24      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:http   io   os   ar   sp   代码   on   c   line   

bubuko.com,布布扣

给出如图三角形里的五个角度,求出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);
		}
	}
}


UVA - 12301-An Angular Puzzle

标签:http   io   os   ar   sp   代码   on   c   line   

原文地址:http://blog.csdn.net/stl112514/article/details/39233981

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!