symmetryTime
limit:3000MS
Memory Limit:0KB
64bit IO Format:%lld &%llu
Description
The figure shown on the left is left-right symmetric as it was possible to fold the sheet of paper along a ve RticalLine, drawn as a dashed line, and to cut the figure into the identical halves. The figure on the right was not left-right symmetric as it was impossible to find such a vertical line.
Write A program This determines whether a figure, drawn with dots, was left-right symmetric or not. The dots is all distinct.
Input
The input consists of T test Cases. The number of test cases T is given on the first line of the input file. The first line of all test case contains an integer n , where N ( 1N1, $) 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 is integers between-10,000 and, Both inclus Ive.
Output
Print exactly one line for each test case. The line should contain 'YES' If the figure is left-right symmetric. and 'NO', otherwise.
The following shows sample input and output for three test cases.
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 105 10 6 14
Sample Output
Yes NO Yes
Test instructions; In the coordinates given in the point, look for a vertical symmetry axis, let these points symmetric about it, if it exists, output yes, otherwise output no
Read a lot of people's blog, most of the problem with the STL solution, it will be easier to understand it, but I do not, so it is a good understanding of their own to avoid the problem of precision (coordinates)
AC Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace Std;
const double eps=1e-5; //1e-5: Floating-point numbers, in the computer so to say, in mathematics is the scientific counting method. 1e-5 means 1 times 10 of the negative 5 power. It's 0.000001 .
int x[1010],y[1010];
int main ()
{
int T;
cin>>t;
while (t--)
{
int n,i,j;;
cin>>n;
Double sum=0;
for (I=1; i<=n; i++)
{
cin>>x[i]>>y[i];
Sum+=x[i];
}
Sum/=n;
for (I=1; i<=n; i++)
{
for (j=1; j<=n; j + +)
{
if (ABS (2*sum-x[i]-x[j]) <eps&&abs (Y[i]-y[j]) <eps)
Break
}
if (j>n) break;
}
if (i>n)
cout<< "YES" <<endl;
Else
cout<< "NO" <<endl;
}
}
Symmetry (problems with the axis of symmetry)