pta 拯救007(Floyd)

7-9 拯救007(25 分)

在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接踩着池子里一系列鳄鱼的大脑袋跳上岸去!(据说当年替身演员被最后一条鳄鱼咬住了脚,幸好穿的是特别加厚的靴子才逃过一劫。)

设鳄鱼池是长宽为100米的方形,中心坐标为 (0, 0),且东北角坐标为 (50, 50)。池心岛是以 (0, 0) 为圆心、直径15米的圆。给定池中分布的鳄鱼的坐标、以及007一次能跳跃的最大距离,你需要告诉他是否有可能逃出生天。

输入格式:

首先第一行给出两个正整数:鳄鱼数量 N(100)和007一次能跳跃的最大距离 D。随后 N 行,每行给出一条鳄鱼的 (x,y) 坐标。注意:不会有两条鳄鱼待在同一个点上。

输出格式:

如果007有可能逃脱,就在一行中输出"Yes",否则输出"No"。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int pic[MAXN][MAXN];
struct Node{
    double x, y;
}num[MAXN];
int main(){
    int N;
    double D;
    scanf("%d%lf", &N, &D);
    int cnt = 0;
    double x, y;
    for(int i = 1; i <= N; ++i){
        scanf("%lf%lf", &x, &y);
        double d = sqrt(x * x + y * y);
        if(dcmp(d, 15) <= 0) continue;//鳄鱼在岛上
        ++cnt;
        if(dcmp(d - 15, D) <= 0){
            pic[0][cnt] = pic[cnt][0] = 1;
        }
        num[cnt].x = x;
        num[cnt].y = y;
    }
    if(D >= 35){
        printf("Yes\n");
        return 0;
    }
    for(int i = 1; i <= cnt; ++i){
        double tmpx = min(fabs(-50 - num[i].x), fabs(50 - num[i].x));
        double tmpy = min(fabs(-50 - num[i].y), fabs(50 - num[i].y));
        if(dcmp(tmpx, D) <= 0 || dcmp(tmpy, D) <= 0){
            pic[i][cnt + 1] = pic[cnt + 1][i] = 1;
        }
    }
    for(int i = 1; i <= cnt; ++i){
        for(int j = i + 1; j <= cnt; ++j){
            double d = sqrt((num[i].x - num[j].x) * (num[i].x - num[j].x) + (num[i].y - num[j].y) * (num[i].y - num[j].y));
            if(dcmp(d, D) <= 0){
                pic[i][j] = pic[j][i] = 1;
            }
        }
    }
    for(int k = 0; k <= cnt + 1; ++k){
        for(int i = 0; i <= cnt + 1; ++i){
            for(int j = 0; j <= cnt + 1; ++j){
                if(pic[i][k] == 1 && pic[k][j] == 1){
                    pic[i][j] = 1;
                }
            }
        }
    }
    if(pic[0][cnt + 1] == 1){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/tyty-Somnuspoppy/p/8618587.html

你可能感兴趣的:(pta 拯救007(Floyd))