Summary of program Design competition in Hunan XTU 1237 Magic Triangle (computational geometry)

Source: Internet
Author: User
Tags acos

At the beginning of this month, we three went to Hunan to participate in the CCPC Hunan Program Design Competition, although the road is far away, the June Xiangtan weather hot and dry, but in the effort together, got a bronze medal, also counted not empty-handed and return. However, through the game, or to find our gap, I hope these months of their own efforts to think, active brush questions, for the September ACM Network Race to prepare!

To talk about this topic, this is also the game to think of the high AC ratio of the topic, but we still did not complete, I would like to summarize the question of some ideas and methods.

Magic Triangleproblem 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 is too disturbing. Mosquito net and mosquito-repellent incense is useless for the Mosquito city.

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

Input

The first line contains an integer T (no more than 10000), which indicates the number of test cases. In the following T-lines, each line contains the integers a and B () indicating the both angle Huangriq has ALR Eady got.

Output

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

Sample Input

1
30 30

Sample Output

30.00

The application of calculating geometry to find the intersection of straight line--cross product

The general equation for a line is f (x) = ax + by + c = 0.

Since we already know the two points of the line, assuming (x0,y0), (x1, y1), then you can get

A = y0–y1, B = x1–x0, c = x0y1–x1y0

So we can represent the two lines separately as

F0 (x) = a0*x + b0*y + c0 = 0, F1 (x) = a1*x + b1*y + C1 = 0

Then the intersection of the two lines should satisfy

A0*x + b0*y +c0 = a1*x + b1*y + C1

This can be launched

x = (B0*C1–B1*C0)/d

y = (A1*C0–A0*C1)/d

D = a0*b1–a1*b0, (d is 0 o'clock, indicates two straight lines parallel)

The two are actually Lianli equations F0 (x) = a0*x + b0*y + c0 = 0, F1 (x) = a1*x + b1*y + C1 = 0 Cross Product application

I j K

A0 B0 C0

A1 B1 C1

XTU 1237 Magic Triangle

The idea of solving the problem is to use the common method of vector calculation in high school, establish the Cartesian coordinate system, and use the inverse application of the two vectors point multiplication.

That is, the following two formulas:

Solve the problem is also recognized that the idea can not be too limited, as the title of the person said that the angle is only to push the angle of the relationship, so lose, turn a way to use vector to solve the problem of geometry is very important means!!!

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 #definePI ACOs (-1.0)6 using namespacestd;7 struct Point8 {9     Doublex;Ten     Doubley; One }; APoint Readpoint (DoubleXDoubley) - { - Point C; thec.x=x; -c.y=y; -     returnC; - } + Point readinsertion (point t0,point t1,point k0,point K1) - { + Point o; A     Doublea0,b0,c0,a1,b1,c1,d; ata0=t0.y-t1.y; -b0=t1.x-t0.x; -c0=t0.x*t1.y-t1.x*t0.y; -a1=k0.y-k1.y; -b1=k1.x-k0.x; -c1=k0.x*k1.y-k1.x*k0.y; inD=a0*b1-a1*B0; -o.x= (B0*C1-B1*C0)/D; too.y= (A1*C0-A0*C1)/D; +     returno; - } the DoubleINS (point A,point B)//the modulus of finding vectors * { $     returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));Panax Notoginseng } - DoubleDot (point a,point o,point B)//multiply two vector coordinates the { +     return(o.x-a.x) * (o.x-b.x) + (O.Y-A.Y) * (o.y-b.y); A } the DoubleReadangle (Point a,point o,point B)//inverse application of vector point multiplication + { -     returnACOs (Fabs (dot (a,o,b))/(INS (a,o) *ins (b,o))); $ } $ intMain () - { -     intt,a,b; theCin>>T; -      while(t--)Wuyi     { theCin>>a>>b; -         DoubleK1,k2,k3; Wu         DoubleR; -K1=tan (( --a) *1.0/( the/PI));//to find the slope of two linear equations AboutK2=tan (( the-B) *1.0/( the/PI)); $ Point a,b,c,d,e,o; -A=readpoint (1, sqrt (3.0));//establishing a Cartesian coordinate system (A,B,C) -B=readpoint (0,0); -C=readpoint (2,0); AD=readpoint (2, k1*2);//in finding a point on the linear equation +E=readpoint (0,-2*K2); theO=readinsertion (b,d,c,e);//finding intersections -R=readangle (O,A,C) * the/PI;//Finding the angle $printf"%.2lf\n", R); the     } the     return 0; the}

Summary of program Design competition in Hunan XTU 1237 Magic Triangle (computational geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.