2022年第十三届JAVA B组国赛

文章目录

    • A.重合次数(模拟)
    • B.数数(数学)

A.重合次数(模拟)

2022年第十三届JAVA B组国赛_第1张图片

Answer:494

这个题目比较坑人,
在这里插入图片描述

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static int N = (int) (1e5 + 10);
    public static void main(String[] args) throws Exception{
        LocalTime st = LocalTime.of(6, 13, 22);
        LocalTime ex = LocalTime.of(14, 36,21);
        int ans = 0;
        while(!st.equals(ex)) {
            int min = st.getMinute();
            int sed = st.getSecond();
            if(min == sed) {
                ans++;
            }
            st = st.plusSeconds(1);
        }
        System.out.println(ans);
    }
}
//502 注意需要-8   

接下来,我们用程序解释一下,为什么需要减去8,我这里给大家说的清楚一点,

2022年第十三届JAVA B组国赛_第2张图片
2022年第十三届JAVA B组国赛_第3张图片
在这里插入图片描述

#include 
using namespace std;
int main() {
    double hs = 1.0 / 3600.0;
    double ms = 1.0 / 60.0;
    double ss = 1.0;
    
    double sth = 6.0;
    double stm = 13.0 + 22 * ms;
    double sts = 22.0;
    
    int ans = 0;
    
    for (int i = 1; i<= 3600*2 ; i ++) {
        cout << sth << ' ' << stm << ' ' << sts << endl;
        
        if (abs(stm / 60.0 - sts / 60.0) < 1e-8)
            ans ++;
        
        
        sts += ss;
        stm += ms;
        
        if (sts == 60) sts = 0;
        
        if (abs(stm - 60) < 1e-8) stm = 0, sth += 1;
        
        if (sth == 14 && abs(stm-36) < 1e-8 && sts == 20.0) {
            break;
        }
    }
    
    cout << ans;
}

B.数数(数学)

2022年第十三届JAVA B组国赛_第4张图片

Answer:25606

质因数分解定理解题即可
在这里插入图片描述

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static int N = (int) (1e5 + 10);
    static int cnt = 0;
    static boolean isPrime[] = new boolean[N];
    static long[] primes = new long[N];
    static Map<Integer, Integer> map = new HashMap<>();
    public static void main(String[] args) throws Exception {
        int ans = 0;
        for (int i = 2333333; i <= 23333333; i++) {
            int ct = getDiv(i);
            if(ct == 12) {
                ans++;
            }
        }
        System.out.println(ans);
    }
    private static int getDiv(int n) {
        map.clear();
        int num = 0;
        int s = 0;
        for(int i = 2; i <= n/i; i++) {
            if(n % i == 0) {
                s = 0;
                    while(n % i == 0) {
                        n = n / i;
                        s++;
                    }
                    num += s;
            }
        }
        if(n > 1) {
             num += 1;
        }
        return num;
    }
}

你可能感兴趣的:(#,蓝桥杯题解,java,开发语言)