[POJ 2588] Snakes

蛇场穿越问题
本文解决了一个有趣的问题:如何判断一个人能否穿过布满蛇的1000x1000的正方形区域而不被咬到。通过使用并查集和计算几何的方法,该程序能够确定入口和出口的位置。

同swustoj 8

Snakes
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1015 Accepted: 341

Description

Buffalo Bill wishes to cross a 1000x1000 square field. A number of snakes are on the field at various positions, and each snake can strike a particular distance in any direction. Can Bill make the trip without being bitten?

Input

Assume that the southwest corner of the field is at (0,0) and the northwest corner at (0,1000). The input consists of a line containing n <= 1000, the number of snakes. A line follows for each snake, containing three real numbers: the (x,y) location of the snake and its strike distance. The snake will bite anything that passes closer than this distance from its location.

Output

Bill must enter the field somewhere between the southwest and northwest corner and must leave somewhere between the southeast and northeast corners. 

If Bill can complete the trip, give coordinates at which he may enter and leave the field. If Bill may enter and leave at several places, give the most northerly. If there is no such pair of positions, print "Bill will be bitten." 

Sample Input

3
500 500 499
0 0 999
1000 1000 200

Sample Output

Bill enters at (0.00, 1000.00) and leaves at (1000.00, 800.00).

并查集+计算几何

#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define N 1010

int dcmp(double x)
{
    if(fabs(x)<EPS) return 0;
    return x<0?-1:1;
}
struct Point
{
    double x,y;
    Point (){}
    Point (double x,double y):x(x),y(y){}
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
    bool operator == (Point p){
        return dcmp(fabs(x-p.x))==0 && dcmp(fabs(y-p.y))==0;
    }
    double operator * (Point p){
        return x*p.x+y*p.y;
    }
    double operator ^ (Point p){
        return x*p.y-y*p.x;
    }
    double length(){
        return sqrt(x*x+y*y);
    }
    double angle(){
        return atan2(y,x);
    }
    bool operator <(const Point &p)const{
        return y<p.y;
    }
};
struct Line
{
    Point s,e;
    Line (){}
    Line (Point s,Point e):s(s),e(e){}
    Point GetPoint(double t){
        return Point(s.x+(e.x-s.x)*t,s.y+(e.y-s.y)*t);
    }
};
struct Circle
{
    Point c;
    double r;
    Circle(){}
    Circle(Point c,double r):c(c),r(r){}
    Point GetPoint(double a){
        return Point(c.x+cos(a)*r,c.y+sin(a)*r);
    }
    /* 0表示相离,1表示相切,2表示相交 */
    pair<int,vector<Point> > CircleInterLine(Line l){
        vector<Point> res;
        double A=l.e.x-l.s.x,B=l.s.x-c.x,C=l.e.y-l.s.y,D=l.s.y-c.y;
        double E=A*A+C*C,F=2*(A*B+C*D),G=B*B+D*D-r*r;
        double delta=F*F-4*E*G;
        if(dcmp(delta)<0) return make_pair(0,res);
        if(dcmp(delta)==0){
            res.push_back(l.GetPoint(-F/(2*E)));
            return make_pair(1,res);
        }
        res.push_back(l.GetPoint((-F-sqrt(delta))/(2*E)));
        res.push_back(l.GetPoint((-F+sqrt(delta))/(2*E)));
        return make_pair(2,res);
    }
    /* -1表示重合,0表示相离,1表示相切,2表示相交 */
    int operator & (Circle C){
        double d=(c-C.c).length();
        if(dcmp(d)==0){
            if(dcmp(r-C.r)==0) return -1;
            return 0;
        }
        if(dcmp(r+C.r-d)<0) return 0;
        if(dcmp(fabs(r-C.r)-d)>0) return 0;
        double a=(C.c-c).angle();
        double da=acos((r*r+d*d-C.r*C.r)/(2*r*d));
        Point p1=GetPoint(a-da),p2=GetPoint(a+da);
        if(p1==p2) return 1;
        return 2;
    }
};

int n;
int f[N];
Line up,down;
Line lft,rgt;
Circle c[N];

void init()
{
    for(int i=0;i<=n+1;i++) f[i]=i;
    up=Line(Point(0,1000),Point(1000,1000));
    down=Line(Point(0,0),Point(1000,0));
    lft=Line(Point(0,0),Point(0,1000));
    rgt=Line(Point(1000,0),Point(1000,1000));
}
int Find(int x)
{
    if(x!=f[x]) f[x]=Find(f[x]);
    return f[x];
}
void UN(int x,int y)
{
    x=Find(x);
    y=Find(y);
    if(x!=y) f[x]=y;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        init();
        for(int i=1;i<=n;i++) scanf("%lf%lf%lf",&c[i].c.x,&c[i].c.y,&c[i].r);
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if((c[i]&c[j])!=0){
                    UN(i,j);
                }
            }
        }
        //上边界
        for(int i=1;i<=n;i++){
            pair<int,vector<Point> > res=c[i].CircleInterLine(up);
            if(res.first!=0) UN(0,i);
        }
        //下边界
        for(int i=1;i<=n;i++){
            pair<int,vector<Point> > res=c[i].CircleInterLine(down);
            if(res.first!=0) UN(i,n+1);
        }
        if(Find(0)==Find(n+1)){ //出不去
            printf("Bill will be bitten.\n");
            continue;
        }
        //左右边界
        vector<Point> p1,p2;
        p1.push_back(Point(0,1000));
        p2.push_back(Point(1000,1000));
        for(int i=1;i<=n;i++){
            pair<int,vector<Point> > res1=c[i].CircleInterLine(lft);
            pair<int,vector<Point> > res2=c[i].CircleInterLine(rgt);
            if(res1.first!=0){
                while(!res1.second.empty()){
                    if(res1.second.back().y>=0 && res1.second.back().y<=1000 && Find(i)==Find(0))
                        p1.push_back(res1.second.back());
                    res1.second.pop_back();
                }
            }
            if(res2.first!=0){
                while(!res2.second.empty()){
                    if(res2.second.back().y>=0 && res2.second.back().y<=1000 && Find(i)==Find(0))
                        p2.push_back(res2.second.back());
                    res2.second.pop_back();
                }
            }
        }
        int i,j;
        sort(p1.begin(),p1.end());
        sort(p2.begin(),p2.end());
        printf("Bill enters at (0.00, %.2f) and leaves at (1000.00, %.2f).\n",p1[0].y,p2[0].y);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/hate13/p/4598163.html

标题SpringBoot智能在线预约挂号系统研究AI更换标题第1章引言介绍智能在线预约挂号系统的研究背景、意义、国内外研究现状及论文创新点。1.1研究背景与意义阐述智能在线预约挂号系统对提升医疗服务效率的重要性。1.2国内外研究现状分析国内外智能在线预约挂号系统的研究与应用情况。1.3研究方法及创新点概述本文采用的技术路线、研究方法及主要创新点。第2章相关理论总结智能在线预约挂号系统相关理论,包括系统架构、开发技术等。2.1系统架构设计理论介绍系统架构设计的基本原则和常用方法。2.2SpringBoot开发框架理论阐述SpringBoot框架的特点、优势及其在系统开发中的应用。2.3数据库设计与管理理论介绍数据库设计原则、数据模型及数据库管理系统。2.4网络安全与数据保护理论讨论网络安全威胁、数据保护技术及其在系统中的应用。第3章SpringBoot智能在线预约挂号系统设计详细介绍系统的设计方案,包括功能模块划分、数据库设计等。3.1系统功能模块设计划分系统功能模块,如用户管理、挂号管理、医生排班等。3.2数据库设计与实现设计数据库表结构,确定字段类型、主键及外键关系。3.3用户界面设计设计用户友好的界面,提升用户体验。3.4系统安全设计阐述系统安全策略,包括用户认证、数据加密等。第4章系统实现与测试介绍系统的实现过程,包括编码、测试及优化等。4.1系统编码实现采用SpringBoot框架进行系统编码实现。4.2系统测试方法介绍系统测试的方法、步骤及测试用例设计。4.3系统性能测试与分析对系统进行性能测试,分析测试结果并提出优化建议。4.4系统优化与改进根据测试结果对系统进行优化和改进,提升系统性能。第5章研究结果呈现系统实现后的效果,包括功能实现、性能提升等。5.1系统功能实现效果展示系统各功能模块的实现效果,如挂号成功界面等。5.2系统性能提升效果对比优化前后的系统性能
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值