2019 蓝桥杯省赛 B 组模拟赛(一)(Java)

结果填空:钟表

手动算一下

class Main {
    public static void main(String[] args) {
        System.out.println("07:55:41");
    }
}

结果填空:青蛙爬井

简单的模拟

class Main {
    public static void main(String[] args) {
        System.out.println("863");
    }
}

结果填空:倍数

手动算,又快又准

class Main {
    public static void main(String[] args) {
        System.out.println("52573230519");
    }
}

结果填空:马的管辖

二进制枚举+搜索

class Main {
    public static void main(String[] args) {
        System.out.println("90");
    }
}

代码填空:LIS

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

public class Main {
	public static final int N = (int)1e5 + 9;
	public static int n = 0;
	public static int[] f = new int[N];
	public static int[] a = new int[N];

	public static int find(int l, int r, int x) {
		while (l < r) {
			int mid = (l + r) / 2;
			if (f[mid] < x) {
				l = mid + 1;
			} else {
				r = mid;
			}
		}
		return l;
	}

	public static int lis() {
		int len = 0;
		for (int i = 0; i < n; i++) {
			int k = find(0, len, a[i]);
			f[k] = a[i];
			if (k == len) {
				len++;
			}
		}
		return len;
	}

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		for (int i = 0; i < n; i++) {
			a[i] = cin.nextInt();
		}
		System.out.println(lis());
	}
}

程序设计:找质数

深刻怀疑这个题Java时限没有拓宽,C++素数筛法一遍过了,Java优化了好多次还是只能过60%。

//过60%
import java.util.*;
import java.math.*;
import java.io.*;

public class Main{
    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);
        int maxn = 1000000 + 10;
        boolean[] a = new boolean[maxn];
        Arrays.fill(a, true);
        a[0] = a[1] = false;
        for(int i = 2; i * i < maxn; i++){
            if(a[i]){
                for(int j = 2; i * j < maxn; j++){
                    a[i*j] = false;
                }
            }
        }
        int[] p = new int[78555];
        int num = 0;
        for(int i = 2; i < maxn; i++){
            if(a[i]) p[num++] = i;
        }
        //System.out.println(num);
        int T = cin.nextInt();
        while(T-- > 0){
            int n = cin.nextInt();
            /*for(int i = 2; ; i++){
                if(a[i] && a[n-i]){
                    System.out.println(i + " " + (n-i));
                    break;
                }
            }*/
            for(int i = 0; i < num; i++){
                if(a[n-p[i]]){
                    System.out.println(p[i] + " " + (n-p[i]));
                    break;
                }
            }
        }
    }
}
//优化程度还没有上述java的高,但是就是过了,玄学
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout << "----------" << endl

typedef long long ll;
const int maxn = 1e5 + 10;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

bool p[MAXN];
void get_prime(){
	memset(p, true, sizeof(p));
	p[0] = p[1] = false;
	for(int i = 2; i*i < MAXN; i++){
		if(p[i]){
			for(int j = 2; i * j < MAXN; j++){
				p[i*j] = false;
			}
		}
	}
}

int main(int argc, char const *argv[]){
	get_prime();
	int T;
	scanf("%d", &T);
	while(T--){
		int n;
		scanf("%d", &n);
		for(int i = 2; ; i++){
			if(p[i] && p[n-i]){
				printf("%d %d\n", i, n-i);
				break;
			}
		}
	}
	return 0;
}

 

你可能感兴趣的:(蓝桥杯,套题记录)