ICPC North America Qualifier Contest 2015 K. UnDetected(并查集)

The Department of Defense has been designing autonomous robots that can infiltrate war zones and other hostile places in order to carry out missions. Now they want to test their latest design, the Penetrator17001700, and they've hired you to help design the test environment.

The test environment is a rectangular field with some sensors placed within the field. Each sensor has a certain radius defining the region within which it can detect a robot. You want to design the field to have as many sensors as possible while still permitting a route across the field that avoids detection.

The field is a region of the coordinate plane defined by 0\leq x \leq 2000≤x≤200 and 0 \leq y \leq 3000≤y≤300. The robot can be modeled by a point that must remain on the field at all times. It starts at the bottom of the field (y = 0)(y=0) and must end at the top of the field (y = 300)(y=300), and must not pass within range of any sensor. There are NN sensor locations given by triples (x,y,r)(x,y,r) of integers, where each (x,y)(x,y) is a point on the field, and rr is its radius of detection. The implied sensor circles may overlap, but will never be tangent with each other nor with the boundary of the field. All sensors are initially inactive. You must find the largest value of kk such that if sensors 1,2,3,\dots,k1,2,3,…,k are activated there is a path for the robot across the field, but no path if the (k+1)\text{st}(k+1)st sensor is also activated. It is guaranteed that there is no path if all NN sensors are activated.

Input

Input begins with a positive integer N \leq 200N≤200. Each of the next NN lines has three space-separated integers, representing x,y,rx,y,r for a sensor, where r \leq 300r≤300. All sensors lie at different (x,y)(x,y) positions. The first three sample inputs below correspond to the figure shown.

Output

Output a single integer (which may be 00) giving the largest kk as described above.

Since the task has 4 samples, PDF is recommended.

输出时每行末尾的多余空格,不影响答案正确性

样例输入1复制

6
36 228 58
164 224 58
88 170 42
93 105 42
167 85 58
28 44 58

样例输出1复制

2

样例输入2复制

6
36 228 58
28 44 58
164 224 58
88 170 42
93 105 42
167 85 58

样例输出2复制

3

样例输入3复制

6
28 44 58
36 228 58
88 170 42
93 105 42
164 224 58
167 85 58

样例输出3复制

4

题意:

现有一个矩形区域:x = 0 到 x = 200, y = 0 到 y = 300。机器人想要从 y = 0 处移动到 y = 300 处,有 n 个传感器按顺序打开,传感器覆盖的区域机器人不能通过,问最多打开多少个传感器,使得机器人还能通过。保证传感器覆盖区域不相切。

思路:

并查集判断左右两边界的连通性

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int N = 205;

int n, fa[N];

struct node
{
    int x, y, r;
} s[N];

bool judge(int i, int j)
{
    if(j == 1)
    {
        if(-s[i].r < s[i].x && s[i].x < s[i].r)
            return 1;
        else
            return 0;
    }
    else if(j == 2)
    {
        if(200 - s[i].r < s[i].x && s[i].x < 200 + s[i].r)
            return 1;
        else
            return 0;
    }
    else
    {
        int x1 = s[i].x;
        int y1 = s[i].y;
        int x2 = s[j].x;
        int y2 = s[j].y;
        if((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) < (s[i].r + s[j].r) * (s[i].r + s[j].r))
            return 1;
        else
            return 0;
    }
}

void init()
{
    for(int i = 1; i <= n + 2; ++i)
    {
        fa[i] = i;
    }
}

int Find(int x)
{
    if(fa[x] != x)
    {
        fa[x] = Find(fa[x]);
    }
    return fa[x];
}

void unionn(int x, int y)
{
    int xx = Find(x);
    int yy = Find(y);
    if(xx != yy)
    {
        fa[xx] = yy;
    }
}

int main()
{
    int x, y, r, cnt;
    scanf("%d", &n);
    init();
    for(int i = 3; i <= n + 2; ++i)
    {
        scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].r);
    }
    bool flag = 0;
    for(int i = 3; i <= n + 2; ++i)
    {
        for(int j = 1; j < i; ++j)
        {
            if(judge(i, j))
            {
                unionn(i, j);
            }
        }
//        cout<<Find(1)<<' '<<Find(2)<<'\n';
        if(Find(1) == Find(2))
        {
            cnt = i - 3;
            flag = 1;
            break;
        }
    }
    if(!flag)
        cnt = n;
    cout<<cnt<<'\n';
    return 0;
}

 

全部评论

相关推荐

牛客52811839...:实习要写出来业务和产出,你这写的像流水账没人看。项目经历也没有,换个极简简历试试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
10354次浏览 92人参与
# 你的实习产出是真实的还是包装的? #
1836次浏览 42人参与
# 米连集团26产品管培生项目 #
5905次浏览 215人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7541次浏览 43人参与
# 简历第一个项目做什么 #
31647次浏览 333人参与
# 重来一次,我还会选择这个专业吗 #
433425次浏览 3926人参与
# 巨人网络春招 #
11320次浏览 223人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
187075次浏览 1122人参与
# 牛客AI文生图 #
21421次浏览 238人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152340次浏览 887人参与
# 研究所笔面经互助 #
118892次浏览 577人参与
# 简历中的项目经历要怎么写? #
310190次浏览 4205人参与
# AI时代,哪些岗位最容易被淘汰 #
63596次浏览 814人参与
# 面试紧张时你会有什么表现? #
30502次浏览 188人参与
# 你今年的平均薪资是多少? #
213065次浏览 1039人参与
# 你怎么看待AI面试 #
180008次浏览 1245人参与
# 高学历就一定能找到好工作吗? #
64323次浏览 620人参与
# 你最满意的offer薪资是哪家公司? #
76476次浏览 374人参与
# 我的求职精神状态 #
448031次浏览 3129人参与
# 正在春招的你,也参与了去年秋招吗? #
363355次浏览 2638人参与
# 腾讯音乐求职进展汇总 #
160628次浏览 1111人参与
# 校招笔试 #
470789次浏览 2964人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务