招行笔试3.27招行信用卡笔试招商银行信用卡笔试
第一题太简单,第二题太难,100行代码没解出来哭了。。。1+0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for (int i = 0; i < N; i++) { int curr = sc.nextInt(); int col, zeroNum = 0; boolean bigtwo = false; for (int j = 0; j < curr; j++) { col = sc.nextInt(); if(col >= 2) bigtwo = true; else if(col == 0) zeroNum++; } if(bigtwo) System.out.println(curr + 1 - zeroNum); else System.out.println(-1); } sc.close(); } }
import java.util.Scanner; public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i < T; i++) { int n = sc.nextInt(); int[] len = new int[n]; int[] wei = new int[n]; int[] len2 = new int[n]; int[] wei2 = new int[n]; for (int j = 0; j < n; j++) { len[i] = sc.nextInt(); len2[i] = len[i]; } for (int j = 0; j < n; j++) { wei[i] = sc.nextInt(); wei2[i] = wei[i]; } sort(len, wei); int[] left = findLogest(wei, n); int res = 0; while (left.length > 0){ left = findLogest(left, left.length); res++; } for (int j = 1; j < n; j++) { if(len[j] == len[j - 1]) res--; } sort(wei2, len2); int[] right = findLogest(len2, n); int cur = 0; while (right.length > 0){ right = findLogest(left, left.length); cur++; } for (int j = 1; j < n; j++) { if(wei2[j] == wei2[j - 1]) cur--; } res = Math.min(res, cur); System.out.println(res); } sc.close(); } private static int[] findLogest(int[] wei, int n) { //求数组最长递增子序列 int[] curr = new int[n + 1]; curr[1] = wei[0]; int len = 1, start = 0, end = len, mid; for (int i = 1; i < n; i++) { if (wei[i] > curr[len]){ len++; curr[len] = wei[i]; }else { start = 1; end = len; while (start <= end){ mid = (start + end) / 2; if(curr[mid] < wei[i]) start = mid + 1; else end = mid - 1; } curr[start] = wei[i]; } } if(n == len) return new int[0]; int[] res = new int[n - len]; //然后返回除了最长递增子序列外其它的元素组成的数组 int j = 0, k = 0; for (int i = 0; i < n; i++) { if(wei[i] != curr[j]){ res[k] = wei[i]; k++; j++; } } return res; } private static void sort(int[] len, int[] wei) { //快排变种(排序一个数组的时候,按照顺序将另一个数组也交换位置) sort(len, wei, 0, len.length - 1); } private static void sort(int[] len, int[] wei, int l, int h) { if(l >= h) return; int j = partition(len, wei, l, h); sort(len, wei, l, j - 1); sort(len, wei, j + 1, h); } public static int partition(int[] nums1, int[] nums2, int l, int h){ int i = l, j = h + 1; int val = nums1[l]; while (true){ while (nums1[++i] < val && i != h); while (nums1[--j] > val && j != l); if(i >= j) break; swap(nums1, nums2, i, j); } swap(nums1, nums2, l, j); return j; } private static void swap(int[] nums1, int[] nums2, int i, int j) { int temp1 = nums1[i], temp2 = nums2[i]; nums1[i] = nums1[j]; nums2[i] = nums2[j]; nums1[j] = temp1; nums2[j] = temp2; } }