UVA 1595 symmetry (axis of symmetry) _uva

Source: Internet
Author: User

Given coordinates, calculate whether can find a vertical line, so that the left and right sides of the point symmetry

Train of thought: The input process calculates the leftmost and the most right boundary, then calculates the midpoint value, then carries on the traversal to each point, if cannot find one point satisfies the x1+x2=mid*2&&y1==y2, then explained that, the direct break, if the traversal is complete, the explanation all conforms to the idea, Description You can find vertical bars.

Import Java.util.Scanner;

public class Main {
	static int maxn = 1000;
	static int[] x = new INT[MAXN+10];
	static int[] y = new int[maxn+10];
	static int mid,n;
	public static void Main (string[] args) {
		Scanner scan = new Scanner (system.in);
		int t = Scan.nextint ();
		while (T--! =0) {
			n = scan.nextint ();
			int lx = 0,RX = 0;
			for (int i=0;i<n;i++) {
				int a = Scan.nextint ();
				Y[i] = Scan.nextint ();
				X[i] = a*2;
				if (X[I]<X[LX]) lx = i;
				if (X[i]>x[rx]) Rx = i
			}
			MID = (X[lx]+x[rx])/2;
			int i = 0;
			for (; i<n;i++) {
				if (!ishave (i)) {break
					;
				}
			}
			if (i>=n) {
				System.out.println ("YES");
			} else{
				System.out.println ("NO");
	
	}} public static Boolean ishave (int i) {for
		(int j=0;j<n;j++) {
			if (y[i]==y[j]&&x[i]+x[j]==2*mid) return true;
		}
		return false;
	}
}


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.