Ural_1207. Median on the plane (Computational ry)

Source: Internet
Author: User
/* The idea is completely messy, so you can write it if you don't have a clear idea at the beginning. I'm dizzy, various wa.

Ideas:

Find the leftmost vertex d in the bottom of all vertices. Then find the link between D and each other and the X-axis
Angle Between (0 <= π because the Y coordinate of D is the smallest ). Then sort from small to large to find the storage array
Point n/2 is another point. */

My code:

# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
# Include <cmath>
# Define PI 3.1415926535

Using namespace STD;

Const int n= 10010;

Struct point {
Double X;
Double Y;
} P [N];

Struct angle {
Double Ang;
Int I;
} A [n];

Point TMP;

Bool CMP (angle A, angle B ){
Return A. Ang <B. Ang;
}
Int main (){
// Freopen ("data. In", "r", stdin );

Int N, I, D, J;
Double B, C;

Scanf ("% d", & N );
Scanf ("% lf", & P [1]. X, & P [1]. y );
B = P [1]. X; C = P [1]. Y; D = 1;

For (I = 2; I <= N; I ++ ){
Scanf ("% lf", & P [I]. X, & P [I]. y );
If (C> P [I]. Y ){
B = P [I]. X; C = P [I]. Y; D = I;
}
If (C = P [I]. Y & B> P [I]. X ){
B = P [I]. X; C = P [I]. Y; D = I;
}
}

For (j = 1, I = 1; I <= N; I ++ ){
If (I! = D ){
A [J]. I = I;
B = P [I]. X-P [D]. X;
C = P [I]. Y-P [D]. Y;
If (B = 0) {A [J ++]. Ang = PI/2; continue ;}
If (C = 0) {A [J ++]. Ang = 0; continue ;}
If (P [I]. x <p [D]. X)
A [J ++]. Ang = pi-atan (C/B );
Else
A [J ++]. Ang = atan (C/B );
}
}
Sort (a + 1, A + N, CMP );
/* For (I = 1; I <n; I ++ ){
Printf ("% lf % d \ n", a [I]. Ang, a [I]. I );
}*/
Printf ("% d \ n", D, a [n/2]. I );
Return 0;
}

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.