2022全国计算机能力挑战赛 java 决赛

整体上来说,难度不大,第二题,第三题,第四题感觉就是在写流水账!没啥大难度!

第一题确实有点儿难度!

第一题:

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0;i<N;i++){
            arr[i] = sc.nextInt();
        }
        int[] sss = new int[10000];
        int len=arr.length;
        int allCombinations=(1<<len)-1; //数组的所有组合数
        //从1开始计算组合
        for(int i=1;i<=allCombinations;i++){
            int[] combinations=new int[len];  //保存该数字对应的组合
            int curPosition=len-1;  //当前所在位置,自后向前
            int number=i;
            while(number!=0){
                //若最低位为1,则取该位置的元素
                if((number&1)==1){
                    combinations[curPosition]=arr[curPosition];
                }
                number=number>>>1;  //无符号右移去除低位
                curPosition--;  //记录下一位
            }
            int num = 0;
            for (int a : combinations){
                num += a;
            }
            sss[num]++;
        }
        int num = 0;
        for (int a : arr){
            num += a;
        }
        sss[num]++;
        System.out.println(sss[M]);

    }

 第二题:

 这道题的第二个测试用例有问题

 public static void main(String[] args) {
        int[] arr = new int[5];
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] so = new int[N];
        int num = 0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            num += a;
            so[i] = a;
            if (a >= 90 && a <= 100)
                arr[0]++;
            if (a >= 80 && a < 90)
                arr[1]++;
            if (a >= 70 && a < 80)
                arr[2]++;
            if (a >= 60 && a < 70)
                arr[3]++;
            if (a < 60)
                arr[4]++;
        }
        double ave = (double) num / N;
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String save = decimalFormat.format(ave);   //平均数
        // 方差:
        double aa = 0.0;
        for (int i : so){
            aa = aa + (i - ave) * (i - ave);
        }
        aa = aa / N;
        aa = Math.sqrt(aa);
        String saa = decimalFormat.format(aa); // 方差!
        //百分比
        double A = (double) arr[0] / N * 100;
        double B = (double) arr[1] / N * 100;
        double C = (double) arr[2] / N * 100;
        double D = (double) arr[3] / N * 100;
        double E = (double) arr[4] / N * 100;

        String SA = decimalFormat.format(A);
        String SB = decimalFormat.format(B);
        String SC = decimalFormat.format(C);
        String SD = decimalFormat.format(D);
        String SE = decimalFormat.format(E);
        System.out.println(save+" "+saa);
        System.out.println("A:"+arr[0]+" "+SA+"%");
        System.out.println("B:"+arr[1]+" "+SB+"%");
        System.out.println("C:"+arr[2]+" "+SC+"%");
        System.out.println("D:"+arr[3]+" "+SD+"%");
        System.out.println("E:"+arr[4]+" "+SE+"%");
    }

第三题

public static void main(String[] args) {
        DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
        Scanner sc = new Scanner(System.in);
        try {
            // 9 - 30
            String s = sc.next();
            Date star = dft.parse("2022-9-30");//开始时间
            Date endDay=dft.parse(s);//结束时间
            Long starTime=star.getTime();
            Long endTime=endDay.getTime();
            Long num=endTime-starTime;//时间戳相差的毫秒数
            int time = (int) (num/24/60/60/1000);   //除以一天的毫秒数
            int b = time % 7;
            if ( b == 0)
                System.out.println("徒步远足");
            else if (b <= 3)
                System.out.println("长跑");
            else {
                System.out.println("爬山");

            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

 第四题:

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] s1 = new int[4];   //单价
        int[] s2 = new int[4];   //数量
        for (int i = 0; i < N; i++) {
            String s = sc.next();
            int a, b;
            switch (s) {
                case "W":
                    a = sc.nextInt();
                    b = sc.nextInt();
                    s1[0] += a * b;
                    s2[0] += b;
                    break;
                case "H":
                    a = sc.nextInt();
                    b = sc.nextInt();
                    s1[1] += a * b;
                    s2[1] += b;
                    break;
                case "B":
                    a = sc.nextInt();
                    b = sc.nextInt();
                    s1[2] += a * b;
                    s2[2] += b;
                    break;
                case "E":
                    a = sc.nextInt();
                    b = sc.nextInt();
                    s1[3] += a * b;
                    s2[3] += b;
                    break;
            }
        }
        double num = 0;
        for (int i = 0; i < 4; i++) {
            if (s2[i] >= 5) {
                num = num + s1[i] * 0.8;
            } else if (s2[i] >= 3){
                num = num + s1[i] * 0.9;
            }else{
                num = num + s1[i];
            }
        }
        int s = sc.nextInt();
        if (s > 10000){
            num = num * 0.9;
        } else if (s >= 5000) {
            num = num * 0.95;
        }
        num = num * 0.95;
        DecimalFormat decimalFormat = new DecimalFormat(".0");
        String ssss = decimalFormat.format(num);
        System.out.println(ssss);
    }

 第五题:

 

第五题不会!
有思路了,但是不太会!

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值