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();
}
}