Java 大学B组 第十届蓝桥杯 2019年国赛真题( 三 )

< V; i++)graph[i] = new ArrayList();while ((line = in.readLine()) != null) {StringTokenizer tok = new StringTokenizer(line);Edge edge = new Edge(tok.nextToken(),tok.nextToken(),table.get(tok.nextToken()),tok.nextToken(),tok.nextToken());graph[edge.v].add(edge);}beijing = table.get("北京");visit[beijing] = true;dfs(beijing, 0, "12:00", 1, new ArrayDeque());System.out.println(V);System.out.println((endDay + V - 1) + "天 "+ endTime);}static void dfs(int city, int day, String time, int vcnt, Deque> deque) {if (day > endDay) return;if (vcnt == V) {for (Edge edge: graph[city]) {if (edge.e == beijing) {int nowDay = day;String nowTime = edge.end;if (nowTime.compareTo(time) > 0) nowDay++;if (nowDay < endDay || nowTime.compareTo(endTime) < 0) {for (String c: deque)System.out.print(c + "<-");System.out.println();endDay = nowDay;endTime = nowTime;}}}} else {for (Edge edge: graph[city]) {if (visit[edge.e]) continue;visit[edge.e] = true;deque.push(edge.city);dfs(edge.e, day + (time.compareTo(edge.start) > 0? 1: 0), edge.end, vcnt + 1, deque);deque.pop();visit[edge.e] = false;}}}static class Edge {int v, e;String city, train, start, end;Edge(String train, String city, int e, String start, String end) {this.v = table.get(city);this.city = city;this.e = e;this.start = start;this.end = end;}}}
再把搜索的结果转换一下
public class Test {public static void main(String[] args) throws IOException {// 28天 09:33System.out.println((28 * 24 + 9) * 60 + 33 - 12 * 60);System.out.println(1440 * 28 + 9 * 60 + 33 - 12 * 60);}}
十月 O I 一场空 , 一道真题见祖宗
#E 序列求和
本题总分:15 分
问题描述
学习了约数后 , 小明对于约数很好奇 , 他发现 , 给定一个正整数 t , 总是可以找到含有 t 个约数的整数 。小明对于含有 t 个约数的最小数非常感兴趣 , 并把它定义为 St。
例如 S1 = 1, S2 = 2, S3 = 4, S4 = 6 , · · ·。
现在小明想知道 , 前 60 个 Si 的和是多少?即 S1 + S2 + · · · + S60 是多少?

Java 大学B组  第十届蓝桥杯 2019年国赛真题

文章插图
答案提交
这是一道结果填空的题 , 你只需要算出结果后提交即可 。本题的结果为一个整数 , 在提交答案时只填写这个整数 , 填写多余的内容将无法得分 。
||

public class Test {public static void main(String[] args) {int res = 0;int[] cnt = new int[62];for (int i = 1; true; i++) {int tmp = factors(i);if (tmp >= 60) {cnt[60] = cnt[61] = i;break;}if (cnt[tmp] == 0) cnt[tmp] = i;}for (int i = 60; i > 0; i--) {if (cnt[i] == 0 || cnt[i] > cnt[i + 1]) cnt[i] = cnt[i + 1];res += cnt[i];}System.out.print(res);}static int factors(long n) {int res = 1, now;for (int i = 2; i * i <= n; i++) {now = 0;while (n % i == 0) {now++;n /= i;}if (now > 0) {res *= now + 1;}}return n <= 1? res: (res << 1);}}
网上的另一种结果的解法
import java.util.HashMap;import java.util.Map;public class Test {static final int[] prime = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541 };public static void main(String[] args) {Map map = new HashMap();long res = 0;map.put(1, 1.0);for (int i = 2; i <= 60; i++)resolve(i, 2, 0, i, map, new int[1024]);for (int i = 1; i <= 60; i++)res += map.get(i);System.out.println(res);}static void resolve(int n, int start, int cur, int val, Map map, int[] buff) {if (val == 1) calc(n, cur, map, buff);else while (start