pat 06-图2. Saving James Bond - Easy Version (25)

/* *********************************************** Author :xryz Email :[email protected] Created Time :5-3 19:23:22 File Name :Saving James Bond - Easy Version.cpp ************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
struct node
{
    double x,y;
}a[100+5];
int n,vis[100+5];
double d;
int dis(node d1,node d2)
{
    if(d*d<(d1.x-d2.x)*(d1.x-d2.x)+(d1.y-d2.y)*(d1.y-d2.y)) return 0;
    return 1;
}
int first(int d1)
{
    if(a[d1].x*a[d1].x+a[d1].y*a[d1].y>(d+15)*(d+15)) return 0;
    else return 1;
}

int safe(node d1)
{
    if(d1.x>=50-d) return 1;
    if(d1.y>=50-d) return 1;
    if(d1.x<=-50+d) return 1;
    if(d1.y<=-50+d) return 1;
    return 0;
}
int dfs(int d1)
{
    int ans=0,i;
    if(safe(a[d1])) ans=1;
    else
    {
        for(i=1;i<=n;i++)
        {
            if(!vis[i]&&dis(a[d1],a[i]))
            {
                vis[i]=1;
                ans=dfs(i);
                if(ans==1) break;
            }
        }
    }
    return ans;
}
int main()
{
    int i,flag;
    while(~scanf("%d%lf",&n,&d))
    {
        a[0].x=a[0].y=0;
        for(i=1;i<=n;i++)
        {
            scanf("%lf%lf",&a[i].x,&a[i].y);
        }
        flag=0;

        for(i=1;i<=n;i++)
        {
            memset(vis,0,sizeof(vis));
            if(!vis[i]&&first(i))
            {
                vis[i]=1;
                flag=dfs(i);
                if(flag) break;
            }
        }

        if(flag) puts("Yes");
        else puts("No");
    }
    return 0;
}

你可能感兴趣的:(pat 06-图2. Saving James Bond - Easy Version (25))