Codeforces Round #618 (Div. 2)(D Aerodynamic)(计算几何)

Codeforces Round #618 (Div. 2)(D Aerodynamic)(计算几何)

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
judge: 点我跳转

Description

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 P P P which is defined by coordinates of its vertices. Define P ( x , y ) P(x,y) P(x,y) as a polygon obtained by translating P P P by vector ( x , y ) → \overrightarrow {(x,y)} (x,y) . The picture below depicts an example of the translation:

在这里插入图片描述

Define T T T as a set of points which is the union of all P ( x , y ) P(x,y) P(x,y) such that the origin ( 0 , 0 ) (0,0) (0,0) lies in P ( x , y ) 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) (x,y) lies in T T T only if there are two points A , B A,B A,B in P P P such that A B → = ( x , y ) → \overrightarrow {AB} = \overrightarrow {(x,y)} AB =(x,y) . One can prove T T T is a polygon too. For example, if P P P is a regular triangle then T T T is a regular hexagon. At the picture below P P P is drawn in black and some P ( x , y ) P(x,y) P(x,y) which contain the origin are drawn in colored:

在这里插入图片描述

The spaceship has the best aerodynamic performance if P P P and T T T are similar. Your task is to check whether the polygons P P P and T T T are similar.

Input

The first line of input will contain a single integer n n n ( 3 ≤ n ≤ 1 0 5 3 \le n \le 10^5 3n105) — the number of points.

The i i i-th of the next n n n lines contains two integers x i , y i x_i, y_i xi,yi ( ∣ x i ∣ , ∣ y i ∣ ≤ 1 0 9 |x_i|, |y_i| \le 10^9 xi,yi109), denoting the coordinates of the i i i-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 P P P and T T T are similar. Otherwise, output “NO” in a separate line. You can print each letter in any case (upper or lower).

Examples

input
4
1 0
4 1
3 4
0 3
output
YES
input
3
100 86
50 0
150 0
output
NO
input
8
0 0
1 0
2 1
3 3
4 6
3 6
2 5
1 3
output
YES

Note

The following image shows the first sample: both P P P and T T T are squares. The second sample was shown in the statements.
在这里插入图片描述

题解

一个图形在包含原点的前提下不断平移,其覆盖的部分形成了一个新的图形,判断这个新图形是否和原来的图形相似。

新图形就相当于把原点贴着图形的边移动图形拼接成的新的图形。

找规律会发现只要原图形是中心对称图形,那么新图形就和原图形相似。

放几个样例:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
而题目已经保证点的顺序是顺时针(其实逆时针也可),我们只需要判断所有的对边是否平行即可。

代码

#include <bits/stdc++.h>
#define maxn 300005
#define _for(i, a) for(int i = 0; i < (a); ++i)
using namespace std;

struct poi {
	int x, y;
	poi() {}
	poi(int x, int y) :x(x), y(y) {}
	bool operator * (const poi &b) {
		if (y == b.y && x == b.x || y == -b.y && x == -b.x) return 1;
		else return 0;
	}
};

int n;
poi a[maxn];

bool sol() {
	if (n & 1) return 0;
	_for(i, n / 2) {
		if (!(poi(a[i + 1].x - a[i].x, a[i + 1].y - a[i].y) * poi(a[(i + 1 + n / 2) % n].x - a[i + n / 2].x, a[(i + 1 + n / 2) % n].y - a[i + n / 2].y))) return 0;
	}
	return 1;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);

	while (cin >> n) {
		_for(i, n) cin >> a[i].x >> a[i].y;
		cout << (sol() ? "YES\n" : "NO\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值