publicstaticintresolve(HashMap<Integer, List<Pair>> map, int start, int end, int size){ boolean[] memo = newboolean[size]; return dfs(map, start, end, memo, 0); }
publicstaticintdfs(HashMap<Integer, List<Pair>> map, int start, int end, boolean[] memo, int current){ if (start == end) return current; memo[start] = true; List<Pair> temp = map.get(start); int res = Integer.MAX_VALUE; for (Pair tempPair : temp) { if (!memo[tempPair.key]) { res = Math.min(res, dfs(map, tempPair.key, end, memo, current + tempPair.value)); } } memo[start] = false; return res; }
publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(), m = scanner.nextInt(), x = scanner.nextInt();
HashMap<Integer, List<Pair>> map = new HashMap<>(); for (int i = 0; i < m; i++) { int a = scanner.nextInt(), b = scanner.nextInt(), l = scanner.nextInt(); if (!map.containsKey(a)) { map.put(a, new ArrayList<>()); } List<Pair> temp = map.get(a); temp.add(new Pair(b, l)); } int res = Integer.MIN_VALUE; for (int i = 1; i <= n; i++) { res = Math.max(res, resolve(map, i, x, n + 1) + resolve(map, x, i, n + 1)); } System.out.println(res); } }
publicstaticclassPair{ public Integer index; public Integer credit;
publicPair(int i, int i1){ this.index = i; this.credit = i1; } }
publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(), m = scanner.nextInt();
HashSet<Integer> res = new HashSet<>(); int[][] credits = newint[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { credits[i][j] = scanner.nextInt(); } }
PriorityQueue<Pair> queue = new PriorityQueue<>((a, b) -> b.credit - a.credit); for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) { queue.add(new Pair(i, credits[i][j])); } if (queue.size() > 0) { int max = queue.peek().credit; Pair temp; while (queue.size() > 0 && (temp = queue.poll()).credit == max) { res.add(temp.index); } } queue.clear(); } System.out.println(res.size()); } }
publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(), b = scanner.nextInt(), m = scanner.nextInt(); long x = scanner.nextLong();
int counter = 0; Set<Long> set = new HashSet<>(); while (true) { x = (a * x + b) % m; if (!set.contains(x)) { set.add(x); counter++; } else { break; } } System.out.println(counter); } }
publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(), m = scanner.nextInt(); int[] nums = newint[n]; for (int i = 0; i < n; i++) { nums[i] = scanner.nextInt(); }
Arrays.sort(nums); int divide;
if (m % n == 0) { divide = m / n - 1; } else { divide = m / n; } int counter = 0, counter1 = 0; for (int num : nums) { if (nums[divide] > num) counter1++; if (nums[divide] == num) counter++; } int temp = (m - counter1 * n) / counter; System.out.format("(%d,%d)\n", nums[divide], nums[temp - 1]); } }
publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(), k = scanner.nextInt(); int mid = (n + 1) / 2; int[] nums = newint[n]; int remember = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) { nums[i] = scanner.nextInt(); if (nums[i] == k) remember = Math.min(remember, Math.abs(mid - i)); } int res = Integer.MAX_VALUE;