ZOJ 1090-The Circumference of the Circle Problem Solving report

Source: Internet
Author: User
Here is the link to the question:

Http://acm.zju.edu.cn/onlinejudge/showProblem.do? ProblemCode = 1090 the topic description is very simple. The coordinates of the three points are given, which are set to A (x1, y1), B (x2, y2), C (x3, y3 ), then obtain the circumference of the circle through these three points (retain two decimal places ). However, it is troublesome to deduce the formula. I did this. First, it is difficult to obtain the diameter of the circumference d = BC/sin a = AC/sin B = AB/sin c according to the same center angle of the same string; therefore, calculate the circumference = BC/sin (a) * PI; where BC is the side length of angle a = sqrt (x2-x3) ^ 2 + (y2-y3) ^ 2 ); as for sin (a), we must calculate by three coordinate, more troublesome, you can use the trigonometric formula: sin (a) = sin (a1-a2) = sin (a1) cos (a2)-cos (a1) sin (a2). a1 and a2 are the angle between the X-ray AC and the X-ray AB respectively. If B, cpoints are all in the First quadrant, apparently there is sin (a1) = (y3-y1)/AC; cos (a1) = (x3-x1)/AC; sin (a2) = (x2-x1)/AB; cos (a2) = (y2-y1)/AB; simplified formula: Perimeter = BC/sin (a) * PI = (AC * AB * BC) /(y3-y1) (x2-x1)-(x3-x1) (y2-y1) * PI; so we can write The following code (in c): the Circumference of The Circle
# Include <stdio. h>
# Include <math. h>
# Define PI 3.141592653589793
# Define DISTANCE (x1, y1, x2, y2) sqrt (x2)-(x1) * (x2)-(x1) + (y2) -(y1) * (y2)-(y1 )))
Void main ()
{
Double x1, x2, x3, y1, y2, y3;
Double d12, d23, d31, k, result;
While (scanf ("% lf", & x1, & y1, & x2, & y2, & x3, & y3 )! = EOF)
{
D12 = DISTANCE (x1, y1, x2, y2 );
D23 = DISTANCE (x2, y2, x3, y3 );
D31 = DISTANCE (x3, y3, x1, y1 );
K = fabs (y3-y1) * (x2-x1)-(x3-x1) * (y2-y1 ));
Result = d12 * d23 * d31/k * PI;
Printf ("%. 2lf \ n", result );
}
}
There are only 18 lines of code and one-time smooth AC, and I found that my solution was ranked first among all solutions.
AC WA PE FPE SF TLE MLE CE Total
1926 (54%) 864 (24%) 8 (0%) 1 (0%) 85 (2%) 275 (7%) 0 (0%) 354 (10%) 3517

Top Submssions by Run Time

Submit Time Language Run Time (MS) Run Memory (KB) User Name
21:49:18 C 0 160 Hoodlum1980
17:35:10 C 0 160 Angel
16:58:56 C ++ 0 176 Xxhhtt
21:35:18 C ++ 0 176 Mart0258
15:21:35 C ++ 0 176 Rorro
13:14:03 C ++ 0 176 Missing08
02:34:20 C ++ 0 176 Watashi @ Zodiac
02:54:43 C ++ 0 176 Watashi @ Zodiac
03:02:27 C ++ 0 176 Watashi @ Zodiac
17:48:05 C ++ 0 184 Lizhen
...

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.