网易16年研发笔试题 - 炮台攻击

来源:互联网 发布:哈利波特英文版 知乎 编辑:程序博客网 时间:2024/04/28 15:32

问题

兰博教训提莫之后,然后和提莫讨论起约德尔人,谈起约德尔人,自然少不了一个人,那 就是黑默丁格——约德尔人历史上最伟大的科学家. 提莫说,黑默丁格最近在思考一个问题:黑默丁格有三个炮台,炮台能攻击到距离它R的敌人 (两点之间的距离为两点连续的距离,例如(3,0),(0,4)之间的距离是5),如果一个炮台能攻击 到敌人,那么就会对敌人造成1×的伤害.黑默丁格将三个炮台放在N*M方格中的点上,并且给出敌人 的坐标. 问:那么敌人受到伤害会是多大?


输入描述

第一行9个整数,R,x1,y1,x2,y2,x3,y3,x0,y0.R代表炮台攻击的最大距离,(x1,y1),(x2,y2),
(x3,y3)代表三个炮台的坐标.(x0,y0)代表敌人的坐标.


输出描述

输出一行,这一行代表敌人承受的最大伤害,(如果每个炮台都不能攻击到敌人,输出0×)


输入例子

1 1 1 2 2 3 3 1 2


输出例子

2x


Java Code

import java.util.Scanner;public class FortAttack {    public static void main(String[] args) {        Scanner scan = new Scanner(System.in);        while (scan.hasNext()) {            int r = scan.nextInt();            int x1 = scan.nextInt();            int y1 = scan.nextInt();            int x2 = scan.nextInt();            int y2 = scan.nextInt();            int x3 = scan.nextInt();            int y3 = scan.nextInt();            int x0 = scan.nextInt();            int y0 = scan.nextInt();            int sum = 0;            if (Distance(x1, y1, x0, y0) < r)                sum++;            if (Distance(x2, y2, x0, y0) < r)                sum++;            if (Distance(x3, y3, x0, y0) < r)                sum++;            System.out.println(sum + "x");        }        scan.close();    }    // 计算二维平面中两点之间的距离,结果向下取整    public static int Distance(int x1, int y1, int x2, int y2) {        return (int) Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));    }}

0 0