EPIC Institute of Technology Round August 2024 (Div. 1 + Div. 2) C. Black Circles

C. Black Circles

time limit per test2 seconds

memory limit per test256 megabytes

There are n circles on a two-dimensional plane. The i-th circle is centered at (xi,yi). Initially, all circles have a radius of 0.

The circles' radii increase at a rate of 1 unit per second.

You are currently at (xs,ys); your goal is to reach (xt,yt) without touching the circumference of any circle (including the moment you reach (xt,yt)). You can move in any direction you want. However, your speed is limited to 1 unit per second.

Please determine whether this is possible.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10^{4}). The description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤10^{5}) — the number of circles.

The next n lines each contain two integers xi, yi (1≤xi,yi≤10^{9}) — the center of each circle.

The final line contains four integers xs, ys, xt, yt (1≤xs,ys,xt,yt≤10^{9}) — the coordinates of the starting point and the goal, respectively.

It is guaranteed that these n+2 points are distinct.

It is guaranteed that the sum of n over all testcases does not exceed 10^{5}.

Output

For each test case, output YES if it is possible to reach the goal without touching the circle boundaries, and output NO otherwise.

You can output Yes and No in any case (for example, strings yEs, yes, Yes, and YES will be recognized as a positive response).

Example

Input

7

3

2 5

2 14

10 13

4 9 9 7

3

10 11

6 9

12 12

14 13 4 8

1

5 7

12 6 11 13

2

1000000000 2

2 1000000000

1 1 2 2

1

999999998 1000000000

999999999 999999999 1 1

1

1000000000 1

1 1000000000 1 1

10

989237121 2397081

206669655 527238537

522705783 380636165

532545346 320061691

207818728 199485303

884520552 315781807

992311437 802563521

205138355 324818663

223575704 395073023

281560523 236279118

216941610 572010615 323956540 794523071

Output

YES

NO

YES

YES

YES

NO

YES

Note

In the first test case, a feasible way of movement is as follows.

【思路分析】

数学+思维+贪心。我们只需要考虑一个离(xt,yt)点最近的点即可,由于半径增加速度和点的移动速度一致,只需要对比距离即可。通常在二维平面内对比距离需要平方以减少误差。

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <cstring>

#define i64 long long

using namespace std;

void solve() {
    i64 n;
    cin >> n;
    i64 x[n],y[n],xs,ys,xt,yt,mind = LLONG_MAX;
    for (int i = 0; i < n; ++i) cin>>x[i]>>y[i];
    cin>>xs>>ys>>xt>>yt;
    for (int i = 0; i < n; ++i) mind = min(mind,(x[i]-xt)*(x[i]-xt)+(y[i]-yt)*(y[i]-yt));
    i64 dis = (xt-xs)*(xt-xs)+(yt-ys)*(yt-ys);
    if (dis>=mind) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值