UVA 1595-symmetry

Source: Internet
Author: User

Idea: First, if these points are symmetrical, then their symmetric axes are x = m (M is the average of all points);

Place these points in a set and then scan each point to calculate its symmetry point for x = m to see if the point is in the set.

If one is not present, the description cannot form a symmetric graphic.

1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <Set>5 using namespacestd;6 7 structpoint{8     intx, y;9Point (intx =0,inty =0): X (x), Y (y) {}Ten     BOOL operator< (ConstPoint & RHS)Const One     { A         returnX < Rhs.x | | (x = = Rhs.x && y <rhs.y); -     } - }; the  - Const intMAXN = ++Ten; - Point P[MAXN]; -  + intMain () - { +     intT, N; A     Set<Point>SP; atscanf"%d", &T); -      while(t--) -     { -         Doubles =0, M; - sp.clear (); -scanf"%d", &n); in          for(inti =0; I < n; i++) -         { toCIN >> p[i].x >>p[i].y; + Sp.insert (P[i]); -s + =p[i].x; the         } *m = S/n;//m:must to is a integer. $         BOOLOK =true;Panax Notoginseng          for(inti =0; I < n; i++) -         { thePoint T ((int) (m*2)-p[i].x, p[i].y); +             if(!Sp.count (t)) A             { theOK =false; +                  Break; -             } $         } $printf"%s\n"Ok?"YES":"NO"); -     } -     return 0; the}

UVA 1595-symmetry

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.