第十四届蓝桥杯三月真题刷题训练——第 2 天

第十四届蓝桥杯三月真题刷题训练——第 2 天

题目1:奇数倍数

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

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

    public static void main(String[] args) throws Exception {
    	
//    	for (int i = 2; i <= 100; i++) {
//    		long num = 2019 * i;
//    		boolean flag = true;
//    		while (num > 0) {
//    			int t = (int)(num % 10);
//    			if ((t & 1) == 0) {
//    				flag = false;
//    				break;
//    			}
//    			num /= 10;
//    		}
//    		if (flag) {
//    			out.print(2019 * i);
//    			break;
//    		}
//    	}

    	out.println("139311");

        out.flush();
        in.close();
    }  
}

题目2:求值

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

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

    public static void main(String[] args) throws Exception {
    	
//    	for (int i = 2; i < 1000000; i++) {
//    		int cnt = 0, end = (int)Math.sqrt(i);
//    		for (int j = 1; j <= end; j++) {
//    			if (i % j == 0) {
//    				cnt += 2;
//    				if (i == j) cnt--;
//    			}
//    		}
//    		if (cnt == 100) {
//    			out.println(i);
//    			break;
//    		}
//    	}

    	out.println("45360");

        out.flush();
        in.close();
    }  
}

题目3:求和

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

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

    static int N = (int)2e5 + 10, n;
    static int[] arr = new int[N], pre = new int[N];
    public static void main(String[] args) throws Exception {
    	n = Integer.parseInt(in.readLine());
    	String[] s = in.readLine().split(" ");
    	for (int i = 1; i <= n; i++) {
    		arr[i] = Integer.parseInt(s[i - 1]);
    		pre[i] = arr[i] + pre[i - 1];
    	}
    	long ans = 0L;
    	for (int i = 1; i <= n; i++) {
    		ans += (long)arr[i] * (pre[n] - pre[i]);
    	}
    	out.println(ans);
    	
        out.flush();
        in.close();
    }  
}

题目4:数位排序

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    
    static int N = (int)1e6 + 10, n, m;
    static Integer[] a = new Integer[N];
    
    public static int helper(int n, int m) {
    	for (int i = 0; i < n; i++) a[i] = i + 1;
    	Arrays.sort(a, 0, n, new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				int a = 0, b = 0, n1 = o1, n2 = o2;
				while (n1 > 0) {
					a += n1 % 10;
					n1 /= 10;
				}
				while (n2 > 0) {
					b += n2 % 10;
					n2 /= 10;
				}
				if (a > b) {
					return 1; 
				} else if (a < b) {
					return -1;
				}
				return o1 - o2;
			}
		});

    	return a[m - 1];
    }

    public static void main(String[] args) throws Exception {
    	n = Integer.parseInt(in.readLine());
    	m = Integer.parseInt(in.readLine());
    	
    	out.println(helper(n, m));

        out.flush();
        in.close();
    }  
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值