DFS--uva11853 Paintball

非常有想法的一道题。

1000 * 1000的地图上,n个圆,求是否能从左边界走到右边界,若可以,求最北边的出入口坐标。

#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

const int maxn = 1000 + 5;

struct circle{

    double x,y,r;

}c[maxn];


bool vis[maxn];

double lpy = 1000,rpy = 1000;

int n;


bool intersect(int a,int b)

{

    double dx = c[a].x - c[b].x;

    double dy = c[a].y - c[b].y;

    if (dx * dx + dy * dy >= (c[a].r + c[b].r) * (c[a].r + c[b].r)) {

        return false;

    }

    return true;

}

bool dfs(int i)

{

    vis[i] = true;

    if (c[i].y - c[i].r <= 0) {

       return false;

    }

    if (c[i].x - c[i].r <= 0) {

        lpy = min(lpy,c[i].y - sqrt(c[i].r * c[i].r - c[i].x * c[i].x));

    }

    if(c[i].x + c[i].r >= 1000)

    {

        rpy = min(rpy,c[i].y - sqrt(c[i].r * c[i].r - (1000 - c[i].x) * (1000 - c[i].x)));

    }

    for (int j = 0; j < n; j ++) {

        if (!vis[j] && intersect(i, j)) {

            if (!dfs(j)) {

                return false;

            }

        }

    }

    return true;

}

void solve(int n)

{

    memset(vis, 0, sizeof(vis));

    for (int i = 0; i < n; i ++) {

        if (!vis[i] && c[i].y + c[i].r >= 1000) {

           if(!dfs(i)) {printf("IMPOSSIBLE\n");return;}

        }

    }

    printf("0.00 %.2lf 1000.00 %.2lf\n",lpy,rpy);


}

int main()

{

    while(scanf("%d",&n) != EOF)

    {

        lpy = 1000,rpy = 1000;

        double x,y,r;

        for (int i = 0; i < n; i ++) {

            scanf("%lf%lf%lf",&x,&y,&r);

            c[i] = {x,y,r};

        }

        solve(n);

    }

    return 0;

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值