【第十四届蓝桥杯三月真题刷题训练——第 13 天 (3.16)& 特殊日期 & 重合次数 & 左移右移 & 近似gcd】

第一题:特殊日期

import java.io.IOException;

public class Main {
    static int[] day = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
    static int divide(int x) {
        int res = 0;
        while(x > 0) {
            res += x % 10;
            x /= 10;
        }
        return res;
    }
    
    public static void main(String[] args) throws IOException {
//        long res = 0;
//        for(int y = 1900; y <= 9999; y++) {
//            if(y % 4 == 0 && y % 100 != 0 || y % 400 == 0) day[2]= 29;
//            else day[2] = 28;
//            int tY = divide(y);
//            for(int m = 1; m <= 12; m++) {
//                int tM = divide(m);
//                for(int d = 1; d <= day[m]; d++) {
//                    int tD = divide(d);
//                    if(tY == tM+tD) res++;
//                }
//            }
//        }
//        
//        System.out.println(res);
        
        System.out.println(70910);
    }
}
【第十四届蓝桥杯三月真题刷题训练——第 13 天 (3.16)& 特殊日期 & 重合次数 & 左移右移 & 近似gcd】_第1张图片

第二题:重合次数

import java.io.IOException;

public class Main {
    
    
    public static void main(String[] args) throws IOException {
//        int res = 0;
//        for(int h = 6; h <= 14; h++) {
//            int m;
//            if(h == 6) m = 13;
//            else m = 0;
//            for(; m <= 59; m++) {
//                int s;
//                if(m == 13 && h == 6) s = 22;
//                else s = 0;
//                for(; s <= 59; s++) {
//                    if(s == 0) continue;
//                    if(m == s) res++;
//                    System.out.println(h + ":" + m + ":" + s);
//                    if(h == 14 && m == 36 && s == 20) {
//                        System.out.println(res);
//                        return;
//                    }
//                }
//            }
//        }
//        
        System.out.println(494);
    }
}
【第十四届蓝桥杯三月真题刷题训练——第 13 天 (3.16)& 特殊日期 & 重合次数 & 左移右移 & 近似gcd】_第2张图片

第三题:左移右移

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;


public class Main {
    static class Node{
        int val;
        Node pre;
        Node next;
        
        public Node() {}
        public Node(int val, Node pre, Node next) {
            this.val = val;
            this.pre = pre;
            this.next = next;
        }
    }

    static Node head, tail;
    static HashMap mp = new HashMap<>();
    
    static void init(int n) {
        head = new Node();
        tail = new Node();
        
        for(int i = 1; i <= n; i++) {
            Node tmp = new Node(i, null, null);
            mp.put(i, tmp);
            if(head.next == null) {
                head.next = tmp;
                tmp.pre = head;
                tail.pre = tmp;
                tmp.next = tail;
            }else {
                tail.pre.next = tmp;
                tmp.pre = tail.pre;
                tmp.next = tail;
                tail.pre = tmp;
            }
        }
    }
    
    static void addL(int x) {
        
        Node t = mp.get(x);
        
        Node tmp = t.pre;

        tmp.next = t.next;
        t.next.pre = tmp;
        
        head.next.pre = t;
        t.next = head.next;
        
        head.next = t;
        t.pre = head;
    }
    
    
    static void addR(int x) {
        Node t = mp.get(x);
        
        Node tmp = t.pre;

        
        tmp.next = t.next;
        t.next.pre = tmp;
        
        tail.pre.next = t;
        t.pre = tail.pre;
        
        t.next = tail;
        tail.pre = t;
    }
    
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);
        
        init(n);
        
        while(m-- > 0) {
            s = br.readLine().split(" ");
            String c = s[0];
            int x = Integer.parseInt(s[1]);
            if("L".equals(c)) {
                addL(x);
            }else {
                addR(x);
            }
        }
        
        while(head.next != tail) {
            head = head.next;
            System.out.print(head.val + " ");
        }
        
        
    }
}
【第十四届蓝桥杯三月真题刷题训练——第 13 天 (3.16)& 特殊日期 & 重合次数 & 左移右移 & 近似gcd】_第3张图片

第一题:近似gcd

明天补齐,写了没完全过

你可能感兴趣的:(蓝桥杯,算法,java,ide,蓝桥杯,开发语言)