• 周二. 4 月 21st, 2026

物嫩软件资讯网

软件资讯来物嫩

2018网易编程射击游戏

admin@wunen

6 月 14, 2025



小易正在玩一款新出的射击游戏

,

这个射击游戏在一个二维平面进行


,


小易在坐标原点


(0,0),


平面上有


n


只怪物


,


每个怪物有所在的坐标


(x[i], y[i])


。小易进行一次射击会把


x


轴和


y


轴上


(


包含坐标原点


)


的怪物一次性消灭。







小易是这个游戏的

VIP

玩家


,


他拥有两项特权操作


:






1

、让平面内的所有怪物同时向任意同一方向移动任意同一距离






2

、让平面内的所有怪物同时对于小易


(0,0)


旋转任意同一角度







小易要进行一次射击。小易在进行射击前

,

可以使用这两项特权操作任意次。



小易想知道在他射击的时候最多可以同时消灭多少只怪物

,

请你帮帮小易。




如样例所示

:




所有点对于坐标原点

(0,0)

顺时针或者逆时针旋转


45°,


可以让所有点都在坐标轴上


,


所以


5


个怪物都可以消灭。




输入描述

:




输入包括三行。



第一行中有一个正整数

n(1 ≤ n ≤ 50),

表示平面内的怪物数量。



第二行包括

n

个整数


x[i](-1,000,000 ≤ x[i] ≤ 1,000,000),


表示每只怪物所在坐标的横坐标


,


以空格分割。



第二行包括

n

个整数


y[i](-1,000,000 ≤ y[i] ≤ 1,000,000),


表示每只怪物所在坐标的纵坐标


,


以空格分割。




输出描述

:




输出一个整数表示小易最多能消灭多少只怪物。




输入例子

1:



5


0 -1 1 1 -1


0 -1 -1 1 1




输出例子

1:



5



import java.util.Scanner;
public class KillMonster {
    public static void main(String[] args){
        //输入所有数据
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for(int i=0;i < n;i++){
            x[i] = sc.nextInt();
        }
        for(int i=0;i < n;i++){
            y[i] = sc.nextInt();
        }

        //创建存储斜率的数组
        int[] slope = new int[n*n];
        int[] verticalSlope = new int[n*n];
        //找出所有斜率组合
        int s=0;
        for(int j=0;j < n;j++){
            for(int k=j+1; k < n;k++){
                if(x[j]-x[k] != 0 && y[j]-y[k] != 0){
                    slope[s] = (x[j]-x[k])/(y[j]-y[k]);
                    if(slope[s] != 0){
                        verticalSlope[s] = -1*(1/slope[s]);
                        //System.out.println(slope[s]);
                        s++;
                    }

                }

            }
        }


        //判断当斜率不为0或者无限大的时候交点个数
        //b1 b2为直线和X Y轴的交点的Y坐标
        //counth countv 为的直线和点交点个数
        //intersection 为两条直线的交点个数
        int b1 = 0;
        int b2 = 0;

        int counth = 0;
        int countv = 0;
        int intersection = 0;

        int temp1=0;
        int temp2=0;
        for(int u=0;u<s;u++){
            for(int i=0;i<n;i++){
                b1 = slope[u]*x[i]-y[i];
                for(int j=0;j<n;j++){
                    b2 = verticalSlope[u]*x[j]-y[j];
                    for(int k=0;k<n;k++){
                        if(y[k] == slope[u]*x[k]-b1){
                            counth++;
                        }
                        if(y[k] == verticalSlope[u]*x[k]-b2){
                            countv++;
                        }
                        if(y[k] == slope[u]*x[k]-b1 && y[k] == verticalSlope[u]*x[k]-b2){
                            intersection++;
                        }
                    }
                    temp1 = counth+countv-intersection;
                    counth = 0;
                    countv = 0;
                    intersection = 0;
                    if(temp1 > temp2){
                        temp2 = temp1;
                    }
                }
            }
        }

        //判断当直线斜率为0的情况
        int xValue = 0;
        int yValue = 0;
        int counth2 = 0;
        int countv2 = 0;
        int intersection2 = 0;
        int temp3 = 0;
        int temp4 = 0;
        for(int u=0;u<n;u++){
            for(int i=0;i<n;i++){
                xValue = x[u];
                yValue = y[i];
                for(int j=0;j<n;j++){
                    if(x[j] == xValue){
                        counth2++;
                    }
                    if(y[j] == yValue){
                        countv2++;
                    }
                    if(x[j] == xValue && y[j] == yValue){
                        intersection2++;
                    }
                }

                temp3 = counth2+countv2-intersection2;
                counth2 = 0;
                countv2 = 0;
                intersection2 = 0;
                if(temp3 > temp4){
                    temp4 = temp3;
                }

            }
        }

        if(temp4 > temp2){
            temp2 = temp4;
        }

        System.out.println(temp2);

    }
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注