pdd笔试Java 全部AC
public class Main1 { static HashMap<Integer, Integer> map; static int[] res; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); map = new HashMap<>(); int max = 0; for (int i = 0; i < n; i++) { int tmin = in.nextInt(); int tmax = in.nextInt(); map.put(tmin, map.getOrDefault(tmin, 0) + 1); map.put(tmax + 1, map.getOrDefault(tmax + 1, 0) - 1); max = Math.max(max, tmax + 1); } res = new int[102]; //-50 -- +50 int sum = 0; int start = -1; int end = -1; for (int i = 0 ; i <= 101; i++) { sum += map.getOrDefault(i - 50, 0); res[i] = sum; if (sum >= k && start == -1) { start = i - 50; } else if (sum >= k && start != -1 && i != 101){ end = i - 50; } } if (start != -1 && end != -1) { System.out.println(start + " " + end); } else { System.out.println("error"); } } }public class Main2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] time = in.next().split(":"); double min = Double.parseDouble(time[1]); double hour = Double.parseDouble(time[0]) % 12; double diff = Math.abs(5.5 * min - 30 * hour); DecimalFormat df = new DecimalFormat("##.#"); diff = diff > 180 ? 360 - diff : diff; System.out.println(df.format(diff)); } }public class Main3 { static int[] x; static int[] y; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); x = new int[n]; y = new int[n]; int count = 0; for (int i = 0; i < n; i++) { x[i] = in.nextInt(); y[i] = in.nextInt(); for (int j = 1; j < i; j++) { for (int k = 0; k < j; k++) { if (det(x[i], y[i], x[j], y[j], x[k], y[k]) == 0) { continue; } else { count++; } } } } System.out.println(count); } private static int det(int x1, int y1, int x2, int y2, int x3, int y3) { return x1 * (y2 - y3) - y1 * (x2 - x3) + 1 * (x2 * y3 - y2 * x3); } }public class Main4 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int[] res = new int[n]; Deque<Integer> max = new ArrayDeque<>(); Deque<Integer> min = new ArrayDeque<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { res[i] = in.nextInt(); while (!max.isEmpty() && max.peek() < i - k + 1) { max.poll(); } while (!max.isEmpty() && res[max.peekLast()] < res[i]) { max.pollLast(); } max.offer(i); while (!min.isEmpty() && min.peek() < i - k + 1) { min.poll(); } while (!min.isEmpty() && res[min.peekLast()] > res[i]) { min.pollLast(); } max.offer(i); min.offer(i); if (i >= k - 1) { int diff = res[max.peek()] - res[min.peek()]; sb.append(diff + " "); } } System.out.println(sb.toString().trim()); } }
顺序记不清了 第一个是温度计 第二个是时间角度 第三个是三角形 第四个是滑窗
#笔试题目#