当前位置: 首页 > news >正文

蓝桥杯 第 28 场 蓝桥入门赛

第一题:

直接输出就行了

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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        System.out.println("I will fight and win");
        scan.close();
    }
}

第二题:

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a > b + c) {
            System.out.println("l");
        } else if (b > a + c) {
            System.out.println("q");
        } else if (c > a + b) {
            System.out.println("b");
        } else {
            System.out.println(-1);
        }
    }
}

 第三题:

原本以为是前缀和的题,结果仔细看完题,就是简单的数学题,因为每一次操作之间互不影响,所以先把所有数求和,然后根据l与r的关系,判断奇偶性,然后对总和相加减即可

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

public class Main {
        public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        long count = 0L;
        for (int i = 0; i < n; i++) {
            count += sc.nextInt();
        }

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int flag = r - l + 1;
            if (flag % 2 == 0) {
                count-=(r-l+1)/2;
            }else{
                count+= r-(r-l+1)/2;
            }
        }
        System.out.println(count);
    }
}

第四题

因为咖啡有无限杯,而且可以按照任意毫升比例调制,所以只需要判断所有咖啡比例中最大浓度和最低浓度与目标浓度的关系即可

// 1:无需package
// 2: 类名必须Main, 不可修改
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[] arr = new int[n];
            for (int j = 0; j < n; j++) {
                arr[j] = sc.nextInt();
            }
            Arrays.sort(arr);
            if (arr[0] > m) {
                System.out.println("NO");
            } else if (arr[n - 1] < m) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
    }
}

第五题:

经典流水线问题,使用Johnson算法,参考这篇文章

Johnson算法 流水线问题 java实现-CSDN博客

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }
        int[] B = new int[n];
        for (int i = 0; i < n; i++) {
            B[i] = sc.nextInt();
        }

        List<int[]> list1 = new ArrayList<>();
        List<int[]> list2 = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (A[i] <= B[i]) {
                list1.add(new int[]{A[i], B[i]});
            } else {
                list2.add(new int[]{A[i], B[i]});
            }
        }
        list1.sort((o1, o2) -> o1[0] - o2[0]);
        list2.sort((o1, o2) -> o2[1] - o1[1]);
        List<int[]> list = new ArrayList<>();
        list.addAll(list1);
        list.addAll(list2);
        int AA = 0;
        int BB = 0;
        for(int[] arrs : list){
            AA+=arrs[0];
            BB = Math.max(AA,BB) + arrs[1];
        }
        System.out.println(Math.max(AA,BB));

    }
}

第六题,找规律

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

public class Main {
    	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = (sc.nextLong() + "").length()+1;
		System.out.println(n*9);
	}
}

相关文章:

  • Java 进阶-全面解析
  • CPT208 Human-Centric Computing 人机交互 Pt.2 Prototype(原型)
  • 算力驱动未来:从边缘计算到高阶AI的算力革命
  • 嵌入式笔试(一)
  • Web应用权限绕过与横向移动
  • 【用Cursor 进行Coding 】
  • LU分解原理与C++实现:从理论到实践
  • NO.76十六届蓝桥杯备战|数据结构-单调栈|发射站|Largest Rectangle in a Histogram(C++)
  • 欧税通香港分公司办公室正式乔迁至海港城!
  • Dify平台
  • 企业级防火墙与NAT网关配置
  • SCimilarity:对人类相似细胞进行可扩展搜索的细胞图谱基础模型
  • 软件反模式全解手册(26种核心模式详解)
  • 【AI提示词】决策专家
  • reid查找余弦相似度计算修正(二)
  • python-64-前后端分离之图书管理系统的Vue前端
  • 面向对象(OOP)
  • 跨浏览器 Tab 通信工具-emit/on 风格 API(仿 mitt)
  • 【Unity】Unity Transform缩放控制教程:实现3D模型缩放交互,支持按钮/鼠标/手势操作
  • Python 快速搭建一个小型的小行星轨道预测模型 Demo