【第十四届蓝桥杯三月真题刷题训练——第 20 天 (3.23)& 纸张尺寸 & 最大数字 & 全排列的价值 & 修路】

第一题:纸张尺寸

import java.io.*;

public class Main {



    static  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String s = br.readLine();
        int n = Integer.parseInt(String.valueOf(s.charAt(1)));
        int p1 = 1189, p2 = 841;

        for(int i = 0; i < n; i++){
            int tmp = p1 / 2;
            p1 = p2;
            p2 = tmp;
        }

        out.println(p1);
        out.println(p2);


        out.flush();
    }

}

第二题:最大数字

import java.util.Scanner;

public class Main {
    static String str;
    static int a, b, len;
    static long res;
    
    
    static void dfs(int pos, long v) {
        if(pos == len) {
            res = Math.max(res, v);
            return;
        }
        int c = str.charAt(pos) - '0';
        int t = Math.min(a, 9-c);
        a -= t;
        dfs(pos+1, v*10+c+t);
        a += t;
        if(b > c) {
            b -= c+1;
            dfs(pos+1, v*10+9);
            b += c+1;
        }
    }
    
    public static void main(String[] args) throws Exception {
        Scanner s = new Scanner(System.in);
        str = s.next();
        a = s.nextInt();
        b = s.nextInt();
        len = str.length();
        dfs(0, 0);
        System.out.println(res);
    }
}

第三题:全排列的价值

第四题:修路

补题中。。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值