Hdu3902 calculates the ry .. Violence

Source: Internet
Author: User

 

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3902

 

Question: A simple polygon of 20000 points determines if it is symmetric...

 

Analysis: During the competition, I never dared to do it. Although I saw so many people coming out, there were also a lot of TLE... The method for enumerating the symmetric axis is denied .. Then I did not speak of a method to enumerate symmetric points. I later found that there was no optimization... I can write a cup (check whether the slope of the symmetric point is the same as that of the fixed highlight, and then determine whether the slope of the line segment in the two Midpoint is perpendicular to the original slope) at last, it took me a long time to get started with TLE ..... Miaowu writes an enumeration symmetric axis when playing a few times (it is convenient to determine whether the distance between all vertices that should be symmetric to the two ends of the symmetric axis is equal ).. AC...

 

My TLE program... I really don't know how to change it... Finally, the order of the symmetric points of the enumeration is changed to 200 + MS. Hit the data .. Server now... It seems that sometimes we have to make a decisive decision when we have TLE and AC... Sometimes it is estimated that it is too late to change the data ..

 

Someone used the enumeration symmetric axis on the Internet to add strong pruning Based on the center of gravity...

The mark is made of a suffix array .... Powerful... Thinking cannot keep up with Daniel's thinking...

 

 

Code:

# Include <stdio. h >#include <algorithm> # include <cmath> # include <iostream> using namespace STD; // const double EPS = 0.000001; # define INF 0x7ffffff7const int n = 20010; struct node {Double X, Y;} A [n]; int N; inline double calk (node & A, node & B) {if (. X = B. x) return INF; elsereturn (. y-b.y)/(. x-b.x);} inline double DIS (node & A, node & B) {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} int judge (int x, int y) {int I, J; double K1, K; node mid; k = calk (A [X], a [y]); Mid. X = (a [X]. X + A [Y]. x)/2; mid. y = (a [X]. Y + A [Y]. y)/2; for (I = N, j = Y + 1; I> J; I --, J ++) {k1 = calk (A [I], A [J]); If (K1! = K) return 0; If (DIS (MID, a [I])! = DIS (MID, a [J]) return 0;} if (I = J & DIS (A [X], a [I])! = DIS (A [Y], a [I]) return 0; for (I = x + 1, j = Y-1; I <j; I ++, j --) {k1 = calk (A [I], a [J]); If (K1! = K) return 0; If (DIS (MID, a [I])! = DIS (MID, a [J]) return 0;} if (I = J & DIS (A [X], a [I])! = DIS (A [Y], a [I]) return 0; return 1;} int judge1 (int x, int y) {int I, j; double K1, k; node mid; k = calk (A [X], a [y]); Mid. X = (a [X]. X + A [Y]. x)/2; mid. y = (a [X]. Y + A [Y]. y)/2; for (I = x + 1, j = Y-1; I <j; I ++, j --) {k1 = calk (A [I], A [J]); If (K1! = K) return 0; If (DIS (MID, a [I])! = DIS (MID, a [J]) return 0;} if (I = J & DIS (A [X], a [I])! = DIS (A [Y], a [I]) return 0; If (DIS (A [1], a [2])! = DIS (A [1], a [n]) return 0; return 1 ;}int main () {int I, flag; while (scanf ("% d ", & N )! = EOF) {for (I = 1; I <= N; I ++) {scanf ("% lf", & A [I]. x, & A [I]. y); // A [I]. x * = 2; // A [I]. y * = 2;} flag = 0; for (I = 2; I <= N; I ++) // The position corresponding to enumeration 1 point {flag = judge (1, i); If (FLAG) break;} If (flag = 0) Flag = judge1 (2, n); If (FLAG) printf ("Yes \ n "); elseprintf ("NO \ n");} return 0 ;}

 

Related Keywords:

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.