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

3.8

题目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 boolean check(int x) {
    	while (x > 0) {
    		int mod = x % 10;
    		if (mod == 2 || mod == 4) return false;
    		x /= 10;
    	}
    	return true;
    }
    
    public static void main(String[] args) throws Exception {
    	
//    	int cnt = 0;
//    	for (int i = 1; i < 2019; i++) {
//    		if (!check(i)) continue;
//    		for (int j = i + 1; j < 2019; j++) {
//    			if (!check(j)) continue;
//    			for (int k = j + 1; k < 2019; k++) {
//    				if (check(k) && i + j + k == 2019) cnt++;
//    			}
//    		}
//    	}
//    	out.println(cnt);
    	out.println(40785);
    	
        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 boolean check(int i, int j) {
    	int num = i * 10000 + 600 + j;
    	return num % 2012 == 0 && num % 3 == 0 && num % 12 == 0;
    }
   
    public static void main(String[] args) throws Exception {
    	
//    	for (int i = 2011; i >= 1900; i--) {
//    		for (int j = 1; j <= 30; j++) {
//    			if (check(i, j)) {
//    				out.println(i + " " + j);
//    				break;
//    			}
//    		}
//    	}
    	
    	out.println("19550604");

        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)));
    
   
    public static void main(String[] args) throws Exception {
    	
    	int n = Integer.parseInt(in.readLine());
    	double cnt1 = 0, cnt2 = 0;
    	for (int i = 0; i < n; i++) {
    		int t = Integer.parseInt(in.readLine());
    		if (t >= 60) cnt1++;
    		if (t >= 85) cnt2++;
    	}
    	out.println(Math.round((cnt1 / n * 100)) + "%");
    	out.println(Math.round((cnt2 / n * 100)) + "%");

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

题目4:最大和

dp,题目已经给了状态转移方程了

f[i] 为从起点出发到点 i 的最大价值,从可以一步到达 i 点的所有点中找到价值最大的即可

f[i] = max(f[i], f[j] + v[i])

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)1e4 + 10, n;
    static int[] a = new int[N], f = new int[N];
    
    public static int getDn(int x) {
    	x = n - x;
    	if (x == 1) return 1;
    	int p = 2;
    	while (p * p <= x) {
    		while (x % p == 0) {
    			return p;
    		}
    		p++;
    	}
    	return x;
    }
    
    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++) {
    		a[i] = Integer.parseInt(s[i - 1]);
    	}
    	Arrays.fill(f, -0x3f3f3f3f);
    	f[1] = a[1];
    	
    	for (int i = 1; i <= n; i++) {
    		int st = i + 1, ed = Math.min(n, getDn(i) + i);
    		for (int j = st; j <= ed; j++) f[j] = Math.max(f[j], f[i] + a[j]);
    	}
    	
    	out.println(f[n]);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值