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