• 2018年蓝桥杯java b组第六题


    标题:递增三元组

    给定三个整数数组
    A = [A1, A2, ... AN],
    B = [B1, B2, ... BN],
    C = [C1, C2, ... CN],
    请你统计有多少个三元组(i, j, k) 满足:

    1. 1 <= i, j, k <= N
    2. Ai < Bj < Ck

    【输入格式】
    第一行包含一个整数N。
    第二行包含N个整数A1, A2, ... AN。
    第三行包含N个整数B1, B2, ... BN。
    第四行包含N个整数C1, C2, ... CN。

    对于30%的数据,1 <= N <= 100
    对于60%的数据,1 <= N <= 1000
    对于100%的数据,1 <= N <= 100000 0 <= Ai, Bi, Ci <= 100000

    【输出格式】
    一个整数表示答案

    【输入样例】
    3
    1 1 1
    2 2 2
    3 3 3

    【输出样例】
    27


    资源约定:
    峰值内存消耗(含虚拟机) < 256M
    CPU消耗 < 1000ms


    请严格按要求输出,不要画蛇添足地打印类似:“请您输入...” 的多余内容。
    所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。
    不要使用package语句。不要使用jdk1.7及以上版本的特性。
    主类的名字必须是:Main,否则按无效代码处理。

    当时大概就是这么写的,不知道有错误没有 ,不过样例过编了

    import java.util.Scanner;
    
    public class Main {
        private static int count=0;
        public static void main(String[] args) {
            Scanner scanner =new Scanner(System.in);
            int N=scanner.nextInt();
            int[] A=new int[N];
            int[] B=new int[N];
            int[] C=new int[N];
            A=put(A,scanner);
            B=put(B,scanner);
            C=put(C,scanner);
            compte(A,B,C);
            System.out.println(count);
        }
    
        private static void compte(int[] a, int[] b, int[] c) {
            for(int i=0;i<a.length;i++){
                for(int j=0;j<b.length;j++){
                    for(int k=0;k<c.length;k++){
                        if(a[i]<b[j]&&b[j]<c[k]){
                            count++;
                        }
                    }
                }
            }
        }
    
        private static int[] put(int[] arr, Scanner scanner) {
            for(int i=0;i<arr.length;i++){
                arr[i]=scanner.nextInt();
            }
            return arr;
        }
    
    }
    View Code
    恐惧源于无知,代码改变世界
  • 相关阅读:
    Node.js的Formidable模块的使用
    call 和 apply方法解析
    JavaScript 数组去重方法总结
    Javascript的this用法
    ubuntu虚拟机安装简单pxe服务器
    [LeetCode]Fraction to Recurring Decimal
    [LeetCode]Largest Number
    [LeetCode]Single Number II
    Git & Github使用总结
    vim配置总结
  • 原文地址:https://www.cnblogs.com/ad-zhou/p/8688409.html
Copyright © 2020-2023  润新知