Niu Ke Xiaobai Yue Race 21-Audio

 

Link: https://ac.nowcoder.com/acm/contest/3947/A
Source: Niuke.com

Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 131072K, other languages 262144K
64bit the IO the Format: LLD%

Title description

Nancy likes music very much.
She can distinguish three different kinds of music at the same time. As it happens, there are three symphonic concerts (sound sources of the same loudness) in a city at the same time. But Nancy didn't want to miss every show, so she wanted to find a place where the loudness of the three concerts would be the same, so that she could enjoy three concerts at the same time!
(Note: It is assumed that the sound propagation will not be affected by obstacles, and the sound propagation meets the inverse square law)

Enter description:

Total three lines: each row two integers X I and Y I , three points are not collinear. Data satisfies: 0 | X I | , | Y I | . 1 0 . 9 .

Output description:

Total line: two real numbers P O S X , P O S Y , represents the location of the concerts Nancy (three decimal places)

 

Input

0 0
1 3
4 2

Output

2.000 1.000

 

 

The basics of computational geometry, which I didn't want to sort out, later saw a blog post that was quite clear, let's reprint it

from:https://blog.nowcoder.net/n/ea2af8cf56314da7aacd99ef38c5da11

 

 

 

Solution one:

According to the distance and relationship of points, directly solve the equation

 

 

 1 #include <bits/stdc++.h>
 2 typedef long long LL;
 3 const int INF=0x3f3f3f3f;
 4 const double eps =1e-8;
 5 const int mod=1e8;
 6 const int maxn=2e5+10;
 7 using namespace std;
 8 
 9 int main()
10 {
11     #ifdef DEBUG
12     freopen("sample.txt","r",stdin);
13     #endif
14     
15     double x1,x2,x3,y1,y2,y3;
16     scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
17     
18     double A1,B1,C1,A2,B2,C2;
19     A1 = 2*(x2-x1);
20     B1 = 2*(y2-y1);
21     C1 = x2*x2+y2*y2-x1*x1-y1*y1;
22     A2 = 2*(x3-x1);
23     B2 = 2*(y3-y1);
24     C2 = x3*x3+y3*y3-x1*x1-y1*y1;
25     
26     double X = (C2-B2*C1/B1)/(A2-B2*A1/B1);
27     double Y = (C1-A1*X)/B1;
28     
29     printf("%.3f %.3f\n",X,Y);
30     
31     return 0;
32 }

 

Solution 2:

We need to ask for a point so that the distance between the point and the three vertices of the triangle is the same, that is, to find the outer center of the triangle (the intersection of the vertical lines of the three sides).

We need to ask for the vertical bisector of any two sides, and then we can find the intersection point.

 

Derivation:
Given a line segment y = kx + b (the coordinate at one end is (x1, y1), the coordinate at the other end is (x2, y2)), find the function analytical formula
of its vertical bisector line where the vertical line is f = k1x + c
∵f⊥y
∴k1 * k = -1, that is, k1 = -1 / k (Note: if the two straight lines are perpendicular to each other, then k1 * k2 = -1)
∴f = -1 / k * x + c, that is f = -x / k + c;
substitute the point ((x1 + x2) / 2, (y1 + y2) / 2) into f = -x / k + c
to get (y1 + y2) / 2 =-(( x1 + x2) / 2) / k + c
is simplified to c = (y1 + y2) / 2 + (x1 + x2) / 2k
∴f = -x / k + c Substitute c to get
f = -x / k + (x1 + x2) / 2k + (y1 + y2) / 2
Substitute k = (y1-y2) / (x1-x2) to get the analytic formula of the vertical line
(assume (x1, y1), (x2, y2) two The analytical formula of the point is y = kx + b, then y1 = kx1 + b, y2 = kx2 + b can be subtracted to obtain k)

 

 

 

 1 #include <bits/stdc++.h>
 2 typedef long long LL;
 3 const int INF=0x3f3f3f3f;
 4 const double eps =1e-8;
 5 const int mod=1e8;
 6 const int maxn=2e5+10;
 7 using namespace std;
 8 
 9 int main()
10 {
11     #ifdef DEBUG
12     freopen("sample.txt","r",stdin);
13     #endif
14     
15     double x1,x2,x3,y1,y2,y3;
16     scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
17     
18     double k,k1,b1,k2,b2;
19     k = (y1-y2)/(x1-x2);
20     k1 = -1/k; b1 = (x1+x2)/2/k+(y1+y2)/2;
21     k = (y1-y3)/(x1-x3);
22     k2 = -1/k; b2 = (x1+x3)/2/k+(y1+y3)/2;
23     
24     double X = (b2-b1)/(k1-k2);
25     double Y = k1*X+b1;
26     
27     printf("%.3f %.3f\n",X,Y);
28     
29     return 0;
30 }

 

 

-

Guess you like

Origin www.cnblogs.com/jiamian/p/12688983.html