本文共 2526 字,大约阅读时间需要 8 分钟。
文章目录
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知识点。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; 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 queue = new LinkedList<>(); for (int i = 1; i <= n; ++i) { 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(); } } 转载地址:http://ozhfk.baihongyu.com/