Guy-Manuel and Thomas are going to build a polygon spaceship.
You’re given a strictly convex (i. e. no three points are collinear) polygon PP which is defined by coordinates of its vertices. Define P(x,y)P(x,y)as a polygon obtained by translating PP by vector (x,y)−→−−(x,y)→. The picture below depicts an example of the translation:
Define TT as a set of points which is the union of all P(x,y)P(x,y) such that the origin (0,0)(0,0) lies in P(x,y)P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y)(x,y) lies in TT only if there are two points A,BA,B in PP such that AB−→−=(x,y)−→−−AB→=(x,y)→. One can prove TT is a polygon too. For example, if PP is a regular triangle then TT is a regular hexagon. At the picture below PP is drawn in black and some P(x,y)P(x,y) which contain the origin are drawn in colored:
The spaceship has the best aerodynamic performance if PP and TT are similar. Your task is to check whether the polygons PP and TT are similar.
Input
The first line of input will contain a single integer nn (3≤n≤1053≤n≤105) — the number of points.
The ii-th of the next nn lines contains two integers xi,yixi,yi (|xi|,|yi|≤109|xi|,|yi|≤109), denoting the coordinates of the ii-th vertex.
It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon.
Output
Output “YES” in a separate line, if PP and TT are similar. Otherwise, output “NO” in a separate line. You can print each letter in any case (upper or lower).
Examples
input
Copy
4
1 0
4 1
3 4
0 3
output
Copy
YES
input
Copy
3
100 86
50 0
150 0
output
Copy
nO
input
Copy
8
0 0
1 0
2 1
3 3
4 6
3 6
2 5
1 3
output
Copy
YES
Note
The following image shows the first sample: both PP and TT are squares. The second sample was shown in the statements.
题意:
给你n个点,让你判断是否中心对称,618场最简单一题?
思路:
由于题目是逆时针给出n个点,其实很简单,先判断n&1,如果是奇数就return no,否则只要枚举node[i]和node[i+n/2]的中点有没有变化就可以了。
代码:
#include
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define ll long long
//#define ll unsigned long long
#define R register int
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
#define pi acos(-1)
#define mea (memset(a,0,sizeof(a)))
#define myit set::iterator
#define myits multiset::iterator
#define v30 (1<<30)-1
#define all(x) (x).begin(),(x).end()
#define maxs *s.rbegin()
using namespace std;
inline ll read(){
ll s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put1(){ puts("YES") ;}
void put2(){ puts("NO") ;}
void put3(){ puts("-1"); }
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
using namespace std;
const int manx = 2e5 + 10;
pair<ll , ll> mp[manx] ;
pair<ll , ll> ans , now ;
int main()
{
ll n;
cin >> n;
for (int i=1;i<=n;i++)
{
cin >> mp[i].first >> mp[i].second;
mp[i].first = mp[i].first << 1;
mp[i].second = mp[i].second << 1;
}
if(n % 2 == 1) return cout << "NO" << '\n' , 0;
now = make_pair((mp[1 + n / 2].first + mp[1].first) / 2 , (mp[1 + n / 2].second + mp[1].second) / 2);
for (int i=1;i<=n/2;i++)
{
ans = make_pair((mp[i + n / 2].first + mp[i].first) / 2 , (mp[i + n / 2].second + mp[i].second) / 2);
if(now.first != ans.first || now.second != ans.second) return cout << "NO" << '\n' , 0;
}
cout << "YES" << '\n';
return 0;
}