2.5蓝桥杯打卡aaaaajava

屠一乐 2023-02-06 00:00:20

1.n数累加

import java.util.Scanner;
import java.util.Arrays;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        //在此输入您的代码...
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0;i < n; i++){
          a[i] = scan.nextInt();
        }
        Arrays.sort(a);
        int res = 0;
        int sum = a[0];
        for(int i = 0;i < n - 1;i++){
          sum+=a[i + 1];
          res+=sum;
        }
        System.out.println(res);
        scan.close();
    }
}

2.接金币

package com.mvc.domain;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author: 屠一乐
 * @date: 2023/2/5 23:27
 * @description:
 */
public class Main {
     static int N = 51;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        while (a-- > 0) {
            int n = scanner.nextInt();
            Node[] nodes = new Node[N];
            for (int i = 1; i <= n; i++) {
                int xx = scanner.nextInt();
                int yy = scanner.nextInt();
                nodes[i] = new Node(xx, yy);
            }

            boolean flag = true;
            Arrays.sort(nodes, 1, n + 1, Comparator.comparingInt(o -> o.y));
            nodes[0] = new Node(0,0);
            for (int i = 1; i <= n; i++) {
                int x = nodes[i].x;
                int y = nodes[i].y;
                int dx = Math.abs(x - nodes[i - 1].x);
                int dy = Math.abs(y - nodes[i - 1].y);
                if (dx > dy) {
                    flag = false;
                    break;
                }
            }
            System.out.println(!flag? "Notabletocatch" : "Abletocatch");
        }

    }

    static class Node {
        int x = 0;
        int y = 0;

        public Node(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

}


...全文
19 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,718

社区成员

发帖
与我相关
我的任务
社区描述
和众多高校算法内卷分子,一起学习和交流算法那。浓郁的算法交流氛围,拒绝躺平,有效内卷。加入我们,私信我拉你入核心内卷群。
算法数据结构leetcode 个人社区
社区管理员
  • 执 梗
  • Dream-Y.ocean
  • ღCauchyོꦿ࿐
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

 刷题!

试试用AI创作助手写篇文章吧