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

特殊日期

原题链接

特殊日期

问题描述

todo:这里复制题目描述

解题思路

模拟即可

参考代码

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[] days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
    public static boolean isLeap(int year) {
    	return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
    }
    
    public static int check(int x) {
    	int ans = 0;
    	while (x > 0) {
    		ans += x % 10;
    		x /= 10;
    	}
    	return ans;
    }
    
    public static void main(String[] args) throws Exception {
    	int ans = 0;
    	for (int i = 1900; i <= 9999; i++) {
    		days[2] = isLeap(i)? 29: 28;
    		for (int j = 1; j <= 12; j++) {
    			for (int k = 1; k <= days[j]; k++) {
    				if (check(i) == check(j) + check(k)) ans++;
    			}
    		}
    	}
    	out.println(ans);
        
        out.flush();
        in.close();
    }  
}

重合次数

原题链接

重合次数

问题描述

todo:这里复制题目描述

解题思路

模拟即可,每 60 秒就会重合一次。注意这个题有个坑,所以就是 60 分钟重合 59 次,折合一下就是每 61 秒重合一次。
在这里插入图片描述

参考代码

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 st = 6 * 60 * 60 + 13 * 60 + 22;
    	int ed = 14 * 60 * 60 + 36 * 60 + 20;
    	
    	out.println((ed - st) / 61);
        
        out.flush();
        in.close();
    }  
}

左移右移

原题链接

左移右移

问题描述

todo:这里复制题目描述

解题思路

每个数的初始权重是它本身,如果移动到最左端,那么它的权重就会变成最小值,最右端同理,最后根据权重排序即可。

参考代码

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, m;
    static int[][] a = new int[N][2];

    public static void main(String[] args) throws Exception {
    	String[] s = in.readLine().split(" ");
    	n = Integer.parseInt(s[0]);
    	m = Integer.parseInt(s[1]);
    	for (int i = 1; i <= n; i++) {
    		 a[i][1] = i;
    		 a[i][0] = i;
    	}
    	int st = 0, ed = n + 1;
    	for (int i = 0; i < m; i++) {
    		s = in.readLine().split(" ");
    		int t = Integer.parseInt(s[1]);
    		if (s[0].equals("L")) {
    			a[t][0] = st--;
    		} else {
    			a[t][0] = ed++;
    		}
    	}
    	Arrays.sort(a, 1, n + 1, (a, b) -> (a[0] - b[0]));
    	for (int i = 1; i <= n; i++) out.print(a[i][1] + " ");
     
        out.flush();
        in.close();
    }  
}

近似gcd

原题链接

近似gcd

问题描述

todo:这里复制题目描述

解题思路

梗子哥这篇题解写的非常的清楚了近似GCD

参考代码

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)1e5 + 10, n, g;
    static int[] a = new int[N];

    public static void main(String[] args) throws Exception {
    	String[] s = in.readLine().split(" ");
    	n = Integer.parseInt(s[0]);
    	g = Integer.parseInt(s[1]);
    	s = in.readLine().split(" ");
    	for (int i = 1; i <= n; i++) {
    		a[i] = Integer.parseInt(s[i - 1]) % g == 0? 1: 0;
    		a[i] += a[i - 1];
    	}
    	long ans = 0L;
    	
    	int start = 0;
    	for (int end = 2; end <= n; end++) {
    		while (start + 1 < end && a[end] - a[start] + 1 < end - start) start++;
    		ans += end - start - 1;
    	}
    	out.println(ans);
     
        out.flush();
        in.close();
    }  
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值