Hengsheng2025春校招编程题

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); // 点的数量
        int[][] points = new int[n][2]; // 点的坐标数组
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            points[i][0] = x; // 横坐标初始化
            points[i][1] = y; // 纵坐标初始化
        }
        int[] k = new int[n-1]; // 斜率数组,两点一线,所以容量减一
        for (int i = 0; i < n - 1; i++) { // 纵坐标之差与横坐标之差的比
            k[i] = (points[i+1][1] - points[i][1]) / (points[i+1][0] - points[i][0]);
        }
        int max = 0;
        int now = 1;
        for (int i = 0; i < n - 1 - 1; i++) {
            if (k[i] < k[i+1]) { // 如果斜率递增
                now++;
            } else {
                max = Math.max(max, now);
                now = 1;
            }
        }
        max = Math.max(max, now);
        if (max == 1)
            System.out.println(-1);
        else
            System.out.println(max);
    }
}
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); // 小电池的总数量
        int q = in.nextInt(); // 询问次数
        int c = in.nextInt(); // 电量阈值
        int[] x = new int[n]; // 横坐标数组
        int[] y = new int[n]; // 纵坐标数组
        int[] s = new int[n]; // 电量数组
        for (int i = 0; i < n; i++) { // 为每个小电池初始化坐标和电量
            x[i] = in.nextInt();
            y[i] = in.nextInt();
            s[i] = in.nextInt();
        }
        for (int _q = 0; _q < q; _q++) { // 每次询问
            int t = in.nextInt(); // 要计算的时刻
            int[] _s = new int[n]; // 临时电量数组
            for (int _t = 0; _t <= t; _t++) { // 从开始到t时刻
                for (int i = 0; i < n; i++) { // 更新每个小电池
                    if (_t == 0) { // 如果是零时刻
                        _s[i] = s[i]; // 复制初始电量
                    } else { // 计算当前时刻电量
                        if (s[i] + 1 <= c) {
                            _s[i]++;
                        } else {
                            _s[i] = 0;
                        }
                    }
                }
            }
            int sum = 0; // 电量之和
            int x1 = in.nextInt();
            int x2 = in.nextInt();
            int y1 = in.nextInt();
            int y2 = in.nextInt();
            for (int i = 0; i < n; i++) { // 遍历每个小电池
                if (x1 <= x[i] && x[i] <= x2) { // 横坐标在区间内
                    if (y1 <= y[i] && y[i] <= y2) { // 纵坐标在区间内
                        sum += _s[i];
                    }
                }
            }
            System.out.println(sum);
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务