XTU1237 Magic Triangle(几何)

Magic Triangle

Accepted : 82
Submit : 186
Time Limit : 1000 MS
Memory Limit : 65536 KB

Magic Triangle

Problem Description:

Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU.

Huangriq works in a big company in Guangzhou now, all things goes well but the mosquitos are too disturbing. Mosquito net and mosquito-repellent incense are useless for this mosquito city.

And finally he decides to use magic to kill them. He make a magic regular triangle as the picture shows. While the most proper position to launch magic is not always the center of circle. In order to make everything smoothly, Huangriq needs to get the value of . And he already get two of them, can you help him to figure out the rest one?

Input

The first line contains a integer T(no more than 10000), which indicates the number of test cases. In the following T lines, each line contains two integers a and b () indicating the two angle Huangriq has already got.

Output

For each test case, output the rest angle's value with two digits after a decimal point in one line.

Sample Input

1
30 30

Sample Output

30.00


Source

XTU OnlineJudge

题意:一个等边三角形内有一点O,已知三个角∠ABO,∠BCO,∠CAO其中两个,求第三个角。
分析:不要老想着找出角之间的关系,只要一开始这么想就错了;多往向量上去想,向量解决几何问题还是挺好解决的(高中知识几乎都还给老师了ㄒoㄒ);运用公式cosA= (AB*AC) / (|AB|*|AC|)(这里的AB和AC是向量)求出cosA,然后arccos(cosA)就是答案了;这样不就简单多了,就只要把O的坐标求出来,而点O是OA,OB,OC三条线的交点,又可以通过已知角求出其中两条的线的斜率,有了斜率就有了直线方程,然后就有了点O的坐标,然后问题不就解决了。

<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))
#define lson (i<<1)
#define rson ((i<<1)|1)
#define MAXN 100010

struct Point
{
    double x,y;
};
Point A,B,C,O;

double Line(Point A, Point B)
{
    return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}

double sub(Point A, Point B)
{
    return A.x*B.x+A.y*B.y;
}

int main()
{
    int T,a,b;
    cin>>T;
    while(T--)
    {
        cin>>a>>b;
        A.x = 1, A.y =  sqrt(3.0);
        B.x = 0, B.y = 0;
        C.x = 2, C.y = 0;
        double k1,k2,b1,b2;///k1是BO的斜率,k2是CO的斜率
        k1 = tan((60-a)*pi/180);
        k2 = tan((180-b)*pi/180);
        b1 = 0.0;
        b2 = -2*k2;
        O.x = (b2-b1)/(k1-k2);
        O.y = k1*O.x + b1;

        double AC = 2;
        double AO = Line(A, O);
        Point t1,t2;///t1表示向量AO,t2表示向量AC
        t1.x = O.x - A.x; t1.y = O.y - A.y;
        t2.x = C.x - A.x; t2.y = C.y - A.y;
        double r = sub(t1, t2)/(AO*AC);
        double ans = acos(r)*180/pi;
        printf("%.2lf\n",ans);
    }
    return 0;
}
</span>


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