zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    自已实现的async 只实现了一部分功能
    async包 ES6 async/await的区别
    网络爬虫基本原理——基于python语言
    推荐一本适合初学者全面自学python的书(附赠电子书)
    用python画小猪票佩奇
    用Python全自动下载抖音视频!
    用python操作PDF文件
    Python爬虫抓取收集考试大纲
    京东商城大规模爬虫的开发
    Python爬虫一步步抓取房产信息
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/8453829.html
Copyright © 2011-2022 走看看