栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Saving James Bond - Easy Version

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Saving James Bond - Easy Version

编程语言:Java
题目:

题解:写着写着一遍过了。
结果:AC

import java.io.*;
import java.util.Scanner;

public class Main {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static Scanner sc = new Scanner(new BufferedInputStream(System.in));

    static crocodile[] c;
    static boolean[] f;
    static double radius=7.5;
    static int n,d;

    public static void main(String[] args) throws IOException {
        n=sc.nextInt();
        d=sc.nextInt();
        c=new crocodile[n];
        f=new boolean[n];
        boolean flag=false;
        for(int i=0;i
            int x=sc.nextInt();
            int y=sc.nextInt();
            c[i]=new crocodile(x,y);
        }
        for(int i=0;i
            if(distance(i)&&dfs(i)){
                out.println("Yes");
                flag=true;
                break;
            }
        }
        if(!flag)
            out.println("No");
        out.flush();
    }

    private static boolean distance(int i) {
        if(Math.sqrt(c[i].x*c[i].x+c[i].y*c[i].y)<=d+radius)
            return true;
        else
            return false;
    }

    private static boolean distance(int i, int j) {
        int x=c[i].x-c[j].x;
        int y=c[i].y-c[j].y;
        if(Math.sqrt(x*x+y*y)<=d)
            return true;
        else
            return false;
    }

    private static boolean dfs(int i) {
        f[i]=true;
        if(Math.abs(c[i].x)>=50-d||Math.abs(c[i].y)>=50-d)
            return true;
        for(int j=0;j
            if(!f[j]&&distance(i,j)&&dfs(j)){
                return true;
            }
        }
        f[i]=false;
        return false;
    }
}
class crocodile{
    int x;
    int y;

    public crocodile(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/835892.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号