## Wednesday, November 25, 2015

### UVa: 1595 - Symmetry

http://blog.csdn.net/crazy__chen/article/details/43544079

Write a program that determines whether a figure, drawn with dots, is left-right symmetric or not. The dots are all distinct.

``` static HashSet<Point> points = new HashSet<Point>();

public static void main(String[] args) {
//测试数据

int sum = 0;
for(Point point : points){
sum += point.x;
}
sum = sum/points.size();//这个就是对称轴

//检查每个点是否存在对称点
for(Point point : points){
if(!points.contains(new Point(sum*2-point.x, point.y))){
System.out.println("不对称");
System.exit(0);
}
}
System.out.println("对称");
}   ```
http://blog.csdn.net/acvay/article/details/43015507

```bool have(int i)
{
for(int j = 0; j < n; ++j)
if(y[i] == y[j] && x[i] + x[j] == 2 * mx) return true;
return false;
}

int main()
{
int cas, lx, rx, a, i;
scanf("%d", &cas);
while(cas--)
{
lx = rx = 0;
scanf("%d", &n);
for(i = 0; i < n; ++i)
{
scanf("%d%d", &a, &y[i]);
x[i] = a * 2;
if(x[i] < x[lx]) lx = i;
if(x[i] > x[rx]) rx = i;
}
mx = (x[lx] + x[rx]) / 2;
for(i = 0; i < n; ++i)
if(!have(i)) break;

if(i >= n) puts("YES");
else puts("NO");
}
return 0;
}```
http://m.blog.csdn.net/blog/qq_15096707/43882793