蓝桥杯31天冲刺打卡题解(Day7)

Day7

第一题

第十二届2021年蓝桥杯省赛

相乘

JavaA组第1题

填空题

签到题。

public class Main {
	public static void main(String[] args) {
		for (long i = 1; i <= 1000000007; i++) {
			long x = i;
			if (x * 2021 % 1000000007 == 999999999) {
				System.out.print(i);
        		return;
			}
		}
	}
}

第二题

第十二届2021年蓝桥杯省赛

空间

C++B组第1题

填空题

签到题,计算机基础知识。

public class Main {
	public static void main(String[] args) {
		/*
			1MB = 1024KB
			1KB = 1024B
			1B = 8bit
			总共有32位 所以还要/32
		*/
		int a = 256 * 1024 / 32 * 1024 * 8 ; // 将32放在前面防止溢出
		System.out.print(a);
	}
}

第三题

第八届2017年蓝桥杯国赛

发现环

C++B组第4题

涉及到的知识点:并查集、拓扑排序或者dfs,知识点还没学,没做出来这道题,贴的蓝桥oj平台的代码。

import java.io.*;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(reader);
        
        in.nextToken();
        int n = (int) in.nval;
        int[][] arr = new int[n + 1][2];
        int[] inNode = new int[n + 1];
        for (int i = 1; i <= n; ++i) {
            in.nextToken();
            int to = (int) in.nval;
            in.nextToken();
            int from = (int) in.nval;
            // 入度+1
            inNode[to]++;
            inNode[from]++;
            // 保存方向
            if (arr[from][0] != 0) {
                arr[from][1]=to;
            } else {
                arr[from][0] = to;
            }
            if (arr[to][0] != 0) {
                arr[to][1]=from;
            } else {
                arr[to][0] = from;
            }
        }
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 1; i <= n; ++i) {
            // 将入度为1的元素放入队列
            if (inNode[i] == 1) {
                queue.add(i);
                inNode[i]--;
            }
        }
        while (!queue.isEmpty()) {
            int cur = queue.poll();
            // 遍历其相邻结点
            for (int t = 0; t <= 1; ++t) {
                int nx = arr[cur][t];
                if (nx != 0) {
                    arr[cur][t] = 0;
                    inNode[nx]--;
                    if (inNode[nx] == 1) {
                        queue.add(nx);
                    }
                }
            }
        }
        for (int i = 1; i <= n; ++i) {
            if (inNode[i] > 1) {
                writer.print(i + " ");
            }
        }
        writer.flush();
    }
}
  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小成同学_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值