全a
01
package huawei; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int n = sc.nextInt(); if ( m < 10 || m > 1000 || n < 10 || n > 1000){ System.out.println("[]"); return; } boolean[][] st = new boolean[m][n]; for (int i = 0; i < m; i++) { Arrays.fill(st[i], false); } int f = 0; int[] xx = {0, 1, 0, -1}; int[] yy = {1, 0, -1, 0}; int x = 0, y = 0; LinkedList<Pair> res = new LinkedList<>(); st[0][0] = true; for (int i = 2; i < (m * n); i++) { x = xx[f] + x; y = yy[f] + y; if ((i % 10 == 7) && (((i % 100) / 10)) % 2 == 1) { res.add(new Pair(x, y)); } st[x][y] = true; while (xx[f] + x < 0 || xx[f] + x == m || yy[f] + y < 0 || yy[f] + y == n || st[xx[f]+x][yy[f]+y]) { f = (++f)%4; } } int[][] out = new int[res.size()][2]; int index = 0; Iterator<Pair> iterator = res.iterator(); while (iterator.hasNext()){ Pair temp = iterator.next(); out[index][0] = temp.x; out[index][1] = temp.y; index++; } System.out.print(Arrays.deepToString(out).replace(" ","")); } static class Pair { public int x; public int y; public Pair(int x, int y) { this.x = x; this.y = y; } } }
02
package huawei; import java.math.BigInteger; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int temp = n; HashMap<Integer, Integer> map = new HashMap<>(); int Max = Integer.MIN_VALUE; while (temp-- != 0) { int i = sc.nextInt(); Max = Math.max(Max, i); if (map.containsKey(i)) { map.replace(i, map.get(i) + 1); } else { map.put(i, 1); } } if (!map.containsKey(0) || map.get(0) != 1) { System.out.println("0"); return; } int i = 1; BigInteger res = new BigInteger("1"); while (map.containsKey(i)) { int new_length = map.get(i); int old_length = map.get(i - 1) * 2; if (new_length > old_length) { System.out.println("0"); return; } res = res.multiply(A(new_length, old_length)); i++; } if (i != (Max +1)){ System.out.println("0"); return; } System.out.println(res.mod(new BigInteger("1000000007"))); } private static BigInteger A(int new_length, int old_length) { if (new_length == old_length) { return new BigInteger("1"); } else { return C(old_length, new_length).divide(C(old_length - new_length, 0)); } } private static BigInteger C(int end, int start) { BigInteger res = BigInteger.valueOf(1); do { start++; res = res.multiply(BigInteger.valueOf(start)); } while (start != end); return res; } }
03
package huawei; import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class Main3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String frame_str = sc.nextLine().trim(); String block_str = sc.nextLine().trim(); int[] frame = new int[frame_str.length()]; int[] block = new int[block_str.length()]; int length = frame_str.length(); int res = Integer.MAX_VALUE; for (int i = 0; i < length; i++) { frame[i] = Integer.parseInt(frame_str.charAt(i) + ""); } for (int i = 0; i < block_str.length(); i++) { block[i] = Integer.parseInt(block_str.charAt(i) + ""); } int[] old_frame = Arrays.copyOf(frame, length); for (int i = 0; i < (length - block_str.length() + 1); i++) { frame = Arrays.copyOf(old_frame, length); for (int j = 0; j < block_str.length(); j++) { frame[i+j] = frame[i+j] + block[j]; } Arrays.sort(frame); res = Math.min(res,frame[length-1]-frame[0]); } System.out.println(res); } }
全部评论
(2) 回帖