通过 100 100 100 27 100(第4不清楚怎么做,骗了27)
移动端代码显示不全,加了图片版, 图片版在上面,代码在下面
注意:aaaa,分割为aa aa,结果应该是1。
如果没考虑到这种情况就只能过55
不会,但是第一个机器人是必选的,所以如果第一个的启动电量大于b,应该直接输出-1,可以过9;另外输出10可以过18;二者结合能过27
注意:有可能用了玩具反而比不用玩具用的时间久。如果没考虑到这种情况就只能过55
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), m = sc.nextInt(); sc.nextLine(); String S = sc.nextLine(), s = sc.nextLine(); int ans = 0; for (int i = 0; i <= n - m; i++) ans += check(s, S.substring(i, i + m), m) ? 1 : 0; System.out.println(ans); } private static boolean check(String s1, String s2, int n) { for (int i = 0; i < n; i++) { if (s1.charAt(i) != '*' && s1.charAt(i) != s2.charAt(i)) return false; } return true; } }
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), m = sc.nextInt(); Map<Integer, Integer> k2v = new HashMap<>(); TreeMap<Integer, Integer> v2k = new TreeMap<>((x, y) -> y - x); for (int i = 0; i < m; i++) { int num = sc.nextInt(); if (k2v.containsKey(num)) { int v = k2v.get(num); v2k.remove(v); k2v.put(num, i); v2k.put(i, num); } k2v.put(num, i); v2k.put(i, num); } for (int v : v2k.keySet()) System.out.print(v2k.get(v) + " "); for (int i = 1; i <= n; i++) { if (!k2v.containsKey(i)) System.out.print(i + " "); } } }
注意:aaaa,分割为aa aa,结果应该是1。
如果没考虑到这种就只能过55
public class Main { static Set<String> set = new HashSet<>(); static boolean[] vis; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] nm = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray(); String str = sc.nextLine(); int[] ms = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray(); String[] substr = new String[nm[1]]; for (int i = 0; i < nm[1]; i++) substr[i] = sc.nextLine(); int sum = Arrays.stream(ms).sum(); vis = new boolean[nm[1]]; dfs(str, ms, nm[1], substr, 0, new LinkedList<String>()); System.out.println(set.size()); } private static void dfs(String str, int[] arr, int n, String[] substr, int level, List<String> list) { if (level == n) { set.add(list.toString()); return; } for (int i = 0; i < n; i++) { if (!vis[i] && str.startsWith(substr[i])) { vis[i] = true; list.add(0, substr[i]); dfs(str.substring(arr[i]), arr, n, substr, level + 1, list); list.remove(0); vis[i] = false; } } } }
不会,但是第一个机器人是必选的,所以如果第一个的启动电量大于b,应该直接输出-1,可以过9;另外输出10可以过18;二者结合能过27
注意:有可能用了玩具反而比不用玩具用的时间久。如果没考虑到这种情况就只能过55
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), k = sc.nextInt(), T = sc.nextInt(); int[][] t = new int[k][2]; for (int i = 0; i < k; i++) { t[i][0] = sc.nextInt(); t[i][1] = i; } Arrays.sort(t, (x, y) -> x[0] - y[0]); int[] toy = new int[k]; long ans = 0L; for (int i = 0; i < n; i++) { int num = sc.nextInt(); if (num == 0) { boolean flag = true; for (int j = 0; j < k; j++) { int idx = t[j][1]; if (toy[idx] > 0) { if (t[j][0] > T) break; ans += t[j][0]; toy[idx]--; flag = false; break; } } if (flag) ans += T; } else toy[num - 1]++; } System.out.println(ans); } }#美团笔试##Java##秋招#