选择题
挑几个记得的来说说
1.CPU低级调度?
进程调度
操作系统还回给老师了。
2.内核锁有哪些?
mutex(互斥信号量)
semaphore (信号量)
rw_semaphore (读写信号量)
Spanlock(自旋锁)
seqlock(顺序锁)
rwlock (读写锁)
RCU(read-copy-update)
BKL(大内核锁)
忘了自己选的啥了
选择题能做个五五开就不错了,基本乱选,不到30分钟搞定,剩下时间的做编程。
编程题
1.完全背包
说小明要买100个物资,每个物资都有自己的价格,在满足物资个数的前提下,求最大价格,同一个物资可买多次,之前当成01背包了,后来在最后一分钟改回来提交一次性通过,吓死!!!!
两次笔试都考到背包问题了,值得重视!
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int total = sc.nextInt(); int n = sc.nextInt(); int[] t = new int[n+1]; int[] v = new int[n+1]; int[][] res = new int[n+1][total+1]; for (int i = 1; i <= n; i++) { t[i] = sc.nextInt(); v[i] = sc.nextInt(); } for (int i = 1; i <= n; i++) { for (int j = 0; j <= total; j++) { res[i][j] = res[i-1][j]; if(j >= t[i] && res[i][j] < res[i][j-t[i]] + v[i]){ res[i][j] = res[i][j - t[i]] + v[i]; } } } System.out.print(res[n][total]); } }2.全排列
[1,2,1]全排列之后的数有多少能被7整除,比如121,111,112这种。
哦,牛批,害我输入输出搞了半天,原来跟leetcode这样直接return的啊,我吐了!回溯来做,比较常规!
import java.util.*; public class Solution { static int count = 0; public int reletive_7 (int[] digit) { // write code here Solution so = new Solution(); fullsort(digit,0,digit.length-1); return count; } public static void fullsort(int[] digit, int start, int end){ if(start == end){ int res = 0; for (int i = 0; i < digit.length; i++) { res = res * 10 + digit[i]; } if(res % 7 == 0) count++; return; } for (int i = start; i <= end ; i++) { swap(digit, i, start); fullsort(digit, start + 1, end); swap(digit, i, start); } } public static void swap(int[] digit, int i, int j){ int tmp = digit[i]; digit[i] = digit[j]; digit[j] = tmp; } }
全部评论
(1) 回帖