1.单选 25*2
2.多选 6 * 2
3.编程题
1)(18)有一个容量为 N 的箱子,希望能够把一些玩具和填充物放入箱子,要求刚好填满。玩具有不同的大小和数量,同时还有体积为 1 的填充物。希望能够通过选择玩具和适当数量的填充物刚好装满箱子。
2)(20)通过在两个数组相应位置交换,最终目的是判断能否将其中一个数组变为非递减或非递增的序列
作者:瞳zoe链接:https://www.nowcoder.com/feed/main/detail/8e1d505a0d9440d791036da0e723606c?sourceSSR=search小米 20240919 算法笔试
package WR; import java.util.Scanner; public class _0919Xiaomi { public static void main1(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t>0){ t--; int N,n,c; N = in.nextInt(); n = in.nextInt(); c = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } if(dfs(a,0,c,N)) System.out.println("YES"); else System.out.println("NO"); } } static boolean dfs(int[] a,int index,int c,int res){ if(res<=c) return true; if(index>=a.length) return false; boolean flag = false; if(res>= a[index]){ flag = dfs(a,index+1,c,res-a[index]); } if(flag) return flag; flag = dfs(a,index+1,c,res); return flag; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); while (T>0){ T--; int n = in.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n; i++) { b[i] = in.nextInt(); } int k = 0; int preNum = -1; boolean flag = true; //尝试升序 while(k<n){ if(a[k]<preNum && b[k]<preNum){ flag = false; break; } if(a[k]<b[k]){ if(a[k]>=preNum){ preNum = a[k]; }else{ preNum = b[k]; } }else { if(b[k]>=preNum){ preNum = b[k]; }else { preNum = a[k]; } } k++; } if (flag){ System.out.println("YES"); continue; }else{ //尝试降序 flag = true; preNum = Integer.MAX_VALUE; k=0; while(k<n){ if(a[k]>preNum && b[k]>preNum){ flag = false; break; } if(a[k]>b[k]){ if(a[k]<=preNum){ preNum = a[k]; }else{ preNum = b[k]; } }else { if(b[k]<=preNum){ preNum = b[k]; }else { preNum = a[k]; } } k++; } if(flag){ System.out.println("YES"); }else{ System.out.println("NO"); } } } } }#小米##笔试##互联网#