UVa 1595 Symmetry(set)

We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper along a vertical line and to cut the figure into two identical halves.For example, if a figure exists five points, which respectively are (-2,5),(0,0),(2,3),(4,0),(6,5). Then we can find a vertical line x = 2 to satisfy this condition. But in another figure which are (0,0),(2,0),(2,2),(4,2), we can not find a vertical line to make this figure left-right symmetric.

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


Input
The input consists of T test cases. The number of test cases T is given in the first line of the input file. The first line of each test case contains an integer N, where N (1 <=N <= 1, 000) is the number of dots in a figure. Each of the following N lines contains the x-coordinate and y-coordinate of a dot. Both x-coordinates and y-coordinates are integers between −10, 000 and 10, 000, both inclusive.


Output
Print exactly one line for each test case. The line should contain 'YES' if the figure is left-right symmetric,and 'NO', otherwise.


Sample Input
3
5
-2 5
0 0
6 5
4 0
2 3
4
2 3
0 4
4 0
0 0
4
5 14
6 10
5 10
6 14

Sample Output
YES
NO
YES

题意

给你n个点,问是否可以找到一条竖线使得所有点对称

题解

首先去找竖线,竖线肯定在中间(注意竖线可以是小数),然后暴力所有点,查询对称点是否存在即可

代码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int,int> pi;
 4 int main()
 5 {
 6     //freopen("in.txt","r",stdin);
 7     //freopen("out.txt","w",stdout);
 8     int T,n,a,b;
 9     cin>>T;
10     while(T--)
11     {
12         set<pi> se;
13         cin>>n;
14         int left=1e9,right=-1e9,F=1;
15         for(int i=0;i<n;i++)
16         {
17             cin>>a>>b;
18             if(left>a)
19                 left=a;
20             if(right<a)
21                 right=a;
22             se.insert(pi(a,b));
23         }
24         double mid=(left+right)*0.5;
25         pi ab;
26         for(auto ab:se)
27         {
28             a=(int)2*mid-ab.first;
29             b=ab.second;
30             if(!se.count(pi(a,b)))
31             {
32                 F=0;
33                 break;
34             }
35         }
36         if(F)cout<<"YES"<<endl;
37         else cout<<"NO"<<endl;
38     }
39     return 0;
40 }

 

转载于:https://www.cnblogs.com/taozi1115402474/p/8453829.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值