├── .pytest_cache ├── README.md └── v │ └── cache │ └── nodeids ├── README.md ├── 算法笔试 ├── 360 │ ├── 1.py │ └── 2.py ├── .pytest_cache │ ├── README.md │ └── v │ │ └── cache │ │ └── nodeids ├── 360_2 │ ├── 1.py │ ├── 2.py │ ├── 3.java │ └── 4.py ├── README.md ├── Tecent │ ├── 1.py │ ├── 2.py │ ├── 3.py │ └── test.py ├── VIPKID │ ├── 1.py │ ├── 2.py │ ├── 3.py │ └── test.py ├── aliyun │ ├── 1.c │ ├── 2.c │ ├── a.out │ └── test.py ├── bilibili │ ├── 1.py │ ├── 2.py │ ├── 3.py │ └── test.py ├── didi │ ├── 1.py │ ├── 1_AC.py │ └── 2.py ├── guanglianda │ ├── 1.py │ ├── 2.py │ └── 3.py ├── guazi │ ├── 1.py │ └── 2.py ├── pinduoduo │ ├── 1.py │ ├── 2.py │ └── 3.py ├── test.py ├── wangyi │ ├── 1.py │ ├── 2.py │ └── 3.py ├── 之江 │ ├── 1.py │ ├── 2.py │ └── test.py ├── 之江2 │ ├── 1.py │ ├── 2.py │ ├── test.py │ └── test1.py ├── 依图 │ ├── 1.py │ ├── 2.py │ ├── 3.py │ ├── 4.py │ └── test.py ├── 商汤 │ ├── 1.py │ ├── 2.py │ └── 3.py ├── 奇安信 │ └── 1.py ├── 小红书 │ ├── 1.py │ ├── 2.py │ └── 3.py ├── 思科 │ ├── 1.py │ ├── 2.py │ └── 3.py ├── 招商银行 │ ├── 1.py │ ├── 2.py │ ├── 3.py │ └── test.py ├── 招行 │ ├── 1.py │ └── 2.py ├── 拼多多_2 │ ├── 1.py │ ├── 2.py │ ├── 3.py │ └── 4.py ├── 携程 │ ├── 1.py │ ├── 2.py │ ├── 3.py │ └── test.cpp ├── 新浪 │ └── 1.py ├── 流利说 │ ├── 1.py │ └── test.java ├── 百度 │ ├── 1.py │ └── 2.py ├── 网易互娱 │ └── 1.py ├── 腾讯2 │ ├── 1.py │ └── 2.py ├── 腾讯3 │ ├── 1.py │ ├── 2.py │ └── 3.py ├── 英特尔 │ ├── 1.py │ └── 2.py ├── 途宿 │ ├── 1.py │ ├── 2.py │ └── test.py ├── 银行 │ ├── 1.py │ └── 2.py ├── 阿里 │ ├── 1.py │ └── 2.py └── 顺丰 │ ├── 1.py │ ├── 2.py │ └── test.py ├── 面试资料 ├── APP汇总整理.md ├── Bagging&Boosting.md ├── Images │ ├── ELUs.png │ ├── PReLU.png │ ├── ReLU_PReLU_RReLU.jpeg │ ├── relu.png │ ├── sigmoid.png │ ├── tanh.png │ ├── 常用神经网络结构图.jpeg │ ├── 损失函数.png │ ├── 百度翻译.html │ └── 百度翻译_files │ │ ├── alog.min.js │ │ ├── app_e8ff780.png │ │ ├── bt_e981bce.swf.下载 │ │ ├── dp.min.js │ │ ├── hm.js │ │ ├── index_90ba2b3.css │ │ ├── index_9d09802.js │ │ ├── loading_50c5e3e.gif │ │ ├── logo_40c4f13.svg │ │ ├── mod_b80b8f9.js │ │ ├── psl.min.js │ │ ├── public_64cf93b.js │ │ ├── public_842c19c.css │ │ ├── saved_resource.html │ │ ├── shitong.js │ │ ├── uni_login_wrapper.js │ │ ├── wechat_76663d3.jpg │ │ └── weibo_669233c.png ├── Python核心知识点.md ├── README.md ├── code │ ├── relu.py │ ├── sigmoid.py │ └── tanh.py ├── offer选择.md ├── 各种类型算法及其应用场景.md ├── 常识知识点杂乱小结.md ├── 损失函数总结.md ├── 机器学习-激活函数总结.md ├── 机器学习_SVM 学习笔记.md ├── 机器学习深度学习结构及相关知识点.md ├── 梯度下降法.md ├── 深度学习优化器.md ├── 神经网络体系汇总.png └── 问题解决步骤.md └── 面试问题及答案汇总 ├── 全知科技-算法工程师_1面.md ├── 全知科技-算法工程师_2面.md ├── 海康威视-AI算法工程师.md ├── 网易严选—优化工程师-2面.md ├── 腾讯-后台开发_1面.md ├── 腾讯-后台开发_2面.md ├── 腾讯-后台开发_3面.md ├── 艾耕科技1面.md ├── 追一科技-算法工程师_1面.md └── 阿里云CDN-机器学习算法.md /.pytest_cache/README.md: -------------------------------------------------------------------------------- 1 | # pytest cache directory # 2 | 3 | This directory contains data from the pytest's cache plugin, 4 | which provides the `--lf` and `--ff` options, as well as the `cache` fixture. 5 | 6 | **Do not** commit this to version control. 7 | 8 | See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information. 9 | -------------------------------------------------------------------------------- /.pytest_cache/v/cache/nodeids: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 面试相关资料 2 | 3 | 主要记录自己的面试经历;包括: 4 | 1、我的面试相关资料(简历、已投公司、相关需求等) 5 | 2、面试需要的知识储备 6 | 3、面试公司的经验以及问题和解答 7 | -------------------------------------------------------------------------------- /算法笔试/.pytest_cache/README.md: -------------------------------------------------------------------------------- 1 | # pytest cache directory # 2 | 3 | This directory contains data from the pytest's cache plugin, 4 | which provides the `--lf` and `--ff` options, as well as the `cache` fixture. 5 | 6 | **Do not** commit this to version control. 7 | 8 | See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information. 9 | -------------------------------------------------------------------------------- /算法笔试/.pytest_cache/v/cache/nodeids: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /算法笔试/360/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Description: In User Settings Edit 3 | @Author: daxiong 4 | @Date: 2019-08-15 18:44:38 5 | @LastEditTime: 2019-08-16 10:52:18 6 | @LastEditors: daxiong 7 | ''' 8 | 9 | 10 | avg = input().strip().split() 11 | N, M = int(avg[0]), int(avg[1]) 12 | arr = [[0]*M for i in range(N)] 13 | 14 | for i in range(N): 15 | line = input().strip().split() 16 | for j in range(M): 17 | arr[i][j] = int(line[j]) 18 | 19 | area = 0 20 | for i in range(N): 21 | for j in range(M): 22 | if arr[i][j] != 0: 23 | area += arr[i][j] * 6 - (arr[i][j] - 1) * 2 24 | if i > 0 and arr[i-1][j] != 0: 25 | area -= min(arr[i-1][j], arr[i][j]) * 2 26 | if j > 0 and arr[i][j-1] != 0: 27 | area -= min(arr[i][j-1], arr[i][j]) * 2 28 | 29 | print(area) 30 | 31 | 32 | # 分为3个部分 33 | # 1. 判断每一个点上的高度,然后如果大于1,则覆盖的面积为高度减1然后乘以2 34 | # 2. 横列减去重叠的 35 | # 3. 纵列减去重叠的 36 | -------------------------------------------------------------------------------- /算法笔试/360/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Description: In User Settings Edit 3 | @Author: daxiong 4 | @Date: 2019-08-15 18:44:38 5 | @LastEditTime: 2019-08-16 10:52:18 6 | @LastEditors: daxiong 7 | ''' 8 | n = 5 9 | m = 5 10 | a = [0,2,4,1,1] 11 | b = [1,1,1,0,0] 12 | 13 | result = dict() 14 | aDict = dict() 15 | bDict = dict() 16 | 17 | for c in set(a): 18 | aDict[c] = a.count(c) 19 | 20 | for c in set(b): 21 | bDict[c] = b.count(c) 22 | 23 | for akey in aDict.keys(): 24 | for bkey in bDict.keys(): 25 | value = (akey + bkey) % m 26 | if value not in result: 27 | result[value] = list() 28 | result[value].append( (akey,bkey) ) 29 | 30 | target = [] 31 | 32 | for i in range(m-1, -1, -1): 33 | if i in result: 34 | for tmp in result[i]: 35 | while tmp[0] in aDict and tmp[1] in bDict: 36 | target.append(i) 37 | aDict[tmp[0]] -=1 38 | bDict[tmp[1]] -=1 39 | if aDict[tmp[0]] == 0: 40 | aDict.pop(tmp[0]) 41 | if bDict[tmp[1]] == 0 : 42 | bDict.pop(tmp[1]) 43 | print(target) 44 | 45 | 46 | # 主要的思想是把第一个数a里面的元素及其个数存储下来,第二个数b里面的元素及其个数存储下来。 47 | # 然后遍历的保存aDict和bDict里面的元素求和模M之后的值,比如为c的话,将后续遍历的所有和模M等于c的值看作一个list保存。这个的复杂度是len(set(a))*len(set(b)),最多为M平方。 48 | # 这样我们就得到了两个数想加的所有和,以及原始值。 49 | # 接下来就从最大的值开始遍历,比如是m-1,然后就找出m-1这个里面在a和b里面的元素分别是什么,在aDict和bDict里面依次减去,直到为0; 50 | # 遍历完结果也就出来了。 -------------------------------------------------------------------------------- /算法笔试/360_2/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 寻找子串 3 | @Author: daxiong 4 | @Date: 2019-08-31 17:30:26 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-05 21:35:24 7 | ''' 8 | 9 | s = input().strip() 10 | s = [_ for _ in s] 11 | p = set(s) 12 | maxNum = 0 13 | for c in p: 14 | if s.count(c) > maxNum: 15 | maxNum = s.count(c) 16 | 17 | print(maxNum) 18 | 19 | # 最多的就是单个字符 -------------------------------------------------------------------------------- /算法笔试/360_2/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 散步 3 | @Author: daxiong 4 | @Date: 2019-08-31 17:42:47 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-31 17:52:43 7 | ''' 8 | 9 | s = input().strip().split() 10 | N = int(s[0]) 11 | M = int(s[1]) 12 | info = list() 13 | for i in range(M): 14 | info.append(int(input().strip())) 15 | 16 | num = set() 17 | 18 | def dfs(d, idx, pos, n, fa): 19 | if idx >= len(d) and pos >= 0 and pos < n: 20 | num.add(pos) 21 | return 22 | if d[idx] <= pos: 23 | dfs(d, idx + 1, pos - d[idx], n, fa) 24 | 25 | if d[idx] <= n - 1- pos: 26 | dfs(d, idx + 1, pos + d[idx], n, fa) 27 | 28 | resNum = 0 29 | for i in range(N): 30 | dfs(info, 0, i, N, i) 31 | 32 | print(num) 33 | print(len(num)) 34 | 35 | 36 | -------------------------------------------------------------------------------- /算法笔试/360_2/3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * @Descripttion: 3 | * @Author: daxiong 4 | * @Date: 2019-08-31 17:46:16 5 | * @LastEditors: daxiong 6 | * @LastEditTime: 2019-08-31 17:46:16 7 | */; 8 | 9 | public class Main { 10 | 11 | public static Set set = new HashSet<>(); 12 | public static void main(String[] args) { 13 | Scanner in = new Scanner(System.in); 14 | 15 | int n = in.nextInt(), m = in.nextInt(); 16 | int[] d = new int[m]; 17 | for (int i = 0; i < m; i++) { 18 | d[i] = in.nextInt(); 19 | } 20 | 21 | for (int i = 0; i < n; i++) { 22 | dfs(d, 0, i, n, i); 23 | } 24 | System.out.println(set.size()); 25 | } 26 | 27 | private static void dfs(int[] d, int idx, int pos, int n, int fa) { 28 | if (idx >= d.length && pos >= 0 && pos < n) { 29 | set.add(pos); 30 | return; 31 | } 32 | if (d[idx] <= pos) { 33 | dfs(d, idx + 1, pos - d[idx], n, fa); 34 | } 35 | 36 | if (d[idx] <= n - pos - 1) { 37 | dfs(d, idx + 1, pos + d[idx], n, fa); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /算法笔试/360_2/4.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-31 20:22:54 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-31 20:27:09 7 | ''' 8 | for i in range(100, 1001): 9 | if i % 10 == 9 and i % 9 == 8 and i % 8 == 7: 10 | print(i) 11 | print(18*108) -------------------------------------------------------------------------------- /算法笔试/README.md: -------------------------------------------------------------------------------- 1 | # 记录笔试的一些算法 2 | 3 | 4 | -------------------------------------------------------------------------------- /算法笔试/Tecent/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-17 19:48:34 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-17 22:01:32 7 | ''' 8 | import sys 9 | if __name__ == "__main__": 10 | a = sys.stdin.readline().strip() 11 | a = list(map(int, a.split())) 12 | n, k = int(a[0]), int(a[1]) 13 | line = sys.stdin.readline().strip() 14 | values = list(map(int, line.split())) 15 | 16 | # n, k = 7, 3 17 | # values = [1, 2, 6, 1, 1, 7, 1] 18 | 19 | temp = values[: k] 20 | num = sum(temp) 21 | result = list() 22 | 23 | for i in range(1, n - k + 1): 24 | result.append(num) 25 | num -= temp[0] 26 | del temp[0] 27 | temp.append(values[(i + k - 1)%n]) 28 | num += temp[-1] 29 | print(result.index(min(result)) + 1) -------------------------------------------------------------------------------- /算法笔试/Tecent/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-17 19:48:39 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-18 10:14:20 7 | ''' 8 | import sys 9 | 10 | def check(result, num, direction): # 1,2,3,4分别表示这个点的上下左右。需要判断是否能行 11 | tag = False 12 | if direction == 1: 13 | if num[0] - 1 >= 0 and result[num[0] - 1][num[1]] > 0: 14 | tag = True 15 | elif direction == 2: 16 | if num[0] + 1 < len(num) and result[num[0] + 1][num[1]] > 0: 17 | tag = True 18 | elif direction == 3: 19 | if num[1] - 1 >= 0 and result[num[0]][num[1] - 1] > 0: 20 | tag = True 21 | else: 22 | if num[1] + 1 < len(result[0]) and result[num[0]][num[1] + 1] > 0: 23 | tag = True 24 | return tag 25 | 26 | if __name__ == "__main__": 27 | t = int(sys.stdin.readline().strip()) 28 | N = list() 29 | M = list() 30 | End1 = list() 31 | End2 = list() 32 | Begin1 = list() 33 | Begin2 = list() 34 | Result = list() 35 | for i in range(t): 36 | a = sys.stdin.readline().strip() 37 | a = list(map(int, a.split())) 38 | n, m = int(a[0]), int(a[1]) # n表示行,m表示列 39 | N.append(N) 40 | M.append(M) 41 | 42 | result = list() # 存储这个数组,在这里我把X记为1,.记为2 43 | for j in range(n): 44 | line = sys.stdin.readline().strip() 45 | values = line 46 | temp = list() 47 | for c in values: 48 | if c == '.': 49 | temp.append(1) 50 | else: 51 | temp.append(0) 52 | result.append(temp) 53 | Result.append(result) 54 | 55 | a = list(map(int, sys.stdin.readline().strip().split())) 56 | beginN, beginM = int(a[0]) - 1, int(a[1]) - 1 # n表示行,m表示列 57 | a = list(map(int, sys.stdin.readline().strip().split())) 58 | endN, endM = int(a[0]) - 1, int(a[1]) - 1 # n表示行,m表示列 59 | Begin1.append(beginN) 60 | Begin2.append(beginM) 61 | End1.append(endN) 62 | End2.append(endM) 63 | 64 | for i in range(t): 65 | n = N[i] 66 | m = M[i] 67 | beginN = Begin1[i] 68 | beginM = Begin2[i] 69 | endN = End1[i] 70 | endM = End2[i] 71 | result = Result[i] 72 | 73 | if result[endN][endM] == 1: 74 | print("YES") 75 | else: 76 | # 直接判断如果上下左右全是1的话,就没办法了 77 | end = (endN, endM) 78 | tag = 1 79 | if check(result, end, 1): 80 | tag *= result[end[0] - 1][end[1]] 81 | if check(result, end, 2): 82 | tag *= result[end[0] + 1][end[1]] 83 | if check(result, end, 3): 84 | tag *= result[end[0]][end[1] - 1] 85 | if heck(result, end, 4): 86 | tag *= result[end[0]][end[1] + 1] 87 | if tag >= 1: 88 | print("YES") 89 | else: 90 | print("NO") 91 | # end = (endN, endM) 92 | # stack = list() 93 | # if check(result, end, 1) == True: 94 | # stack.append((end[0] - 1, end[1])) 95 | # result[end[0] - 1][end[1]] -= 1 96 | # if check(result, end, 2) == True: 97 | # stack.append((end[0] + 1, end[1])) 98 | # result[end[0] + 1][end[1]] -= 1 99 | # if check(result, end, 3) == True: 100 | # stack.append((end[0], end[1] - 1)) 101 | # result[end[0]][end[1] - 1] -= 1 102 | # if check(result, end, 4) == True: 103 | # stack.append((end[0], end[1] + 1)) 104 | # result[end[0]][end[1] + 1] -= 1 105 | # tag = False 106 | # index = 0 107 | # print(result) 108 | # while stack != []: 109 | # print(stack) 110 | # temp = stack.pop(0) 111 | # if temp == end: 112 | # tag = True 113 | # break 114 | # if check(result, temp, 1) == True: 115 | # stack.append((temp[0] - 1, temp[1])) 116 | # result[temp[0] - 1][temp[1]] -= 1 117 | # if check(result, temp, 2) == True: 118 | # stack.append((temp[0] + 1, temp[1])) 119 | # result[temp[0] + 1][temp[1]] -= 1 120 | # if check(result, temp, 3) == True: 121 | # stack.append((temp[0], temp[1] - 1)) 122 | # result[temp[0]][temp[1] - 1] -= 1 123 | # if check(result, temp, 4) == True: 124 | # stack.append((temp[0], temp[1] + 1)) 125 | # result[temp[0]][temp[1] + 1] -= 1 126 | # if tag == True: 127 | # print("YES") 128 | # else: 129 | # print("NO") 130 | # print(result) 131 | 132 | 133 | 134 | # 需要往上下左右四个方向走,走完一个该方向上的数字减1,如果为0则不能再走列。 135 | # 判断是都有这样的数字可以走,BFS?,对的,使用BFS一定可以做,也就是是不是可以两遍走到。 -------------------------------------------------------------------------------- /算法笔试/Tecent/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-17 19:48:45 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-17 19:53:04 7 | ''' 8 | -------------------------------------------------------------------------------- /算法笔试/Tecent/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-17 19:48:50 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-17 20:05:05 7 | ''' 8 | import sys 9 | for line in sys.stdin: 10 | a = line.split() 11 | print(int(a[0]) + int(a[1])) 12 | 13 | 14 | import sys 15 | if __name__ == "__main__": 16 | # 读取第一行的n 17 | n = int(sys.stdin.readline().strip()) 18 | ans = 0 19 | for i in range(n): 20 | # 读取每一行 21 | line = sys.stdin.readline().strip() 22 | # 把每一行的数字分隔后转化成int列表 23 | values = list(map(int, line.split())) 24 | for v in values: 25 | ans += v 26 | print(ans) -------------------------------------------------------------------------------- /算法笔试/VIPKID/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 二进制表示1的个数 3 | @Author: daxiong 4 | @Date: 2019-09-03 15:55:46 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 16:41:56 7 | ''' 8 | a = int(input().strip()) 9 | resNum = 0 10 | while a != 0: 11 | a &= a - 1 12 | resNum += 1 13 | 14 | print(resNum) -------------------------------------------------------------------------------- /算法笔试/VIPKID/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-03 15:55:51 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-25 20:33:40 7 | ''' 8 | s = input().strip().split() 9 | s = [int(i) for i in s] 10 | 11 | newArr = list() # 以类似插入排序的方式 12 | newArr.append(s[0]) 13 | 14 | resNum = 0 # 能力值 15 | maxNum = 0 # 最大的值 16 | priorNum = s[0] # 前面一个数 17 | sameNum = 0 # 相同的值 18 | littleNum = 0 # 小于当前数的个数 19 | biggerNum = 0 # 大于当前数的个数 20 | lenList = 1 # 当前数组的总长 21 | curIndex = 0 22 | 23 | for num in s[1:]: 24 | if num == priorNum: 25 | resNum = resNum + littleNum - biggerNum 26 | elif num < priorNum: 27 | while curIndex >= 0 and newArr[curIndex] > num: 28 | curIndex -= 1 29 | else: 30 | 31 | priorNum = num 32 | lenList += 1 33 | if resNum > maxNum: 34 | maxNum = resNum 35 | -------------------------------------------------------------------------------- /算法笔试/VIPKID/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-25 20:34:43 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-25 20:34:43 7 | ''' 8 | C = int(input()) 9 | 10 | for c in range(C): 11 | n = int(input()) 12 | mis = list(map(int, input().split(" "))) 13 | max_pow = 0 14 | power = [0]*n 15 | 16 | for i in range(1, n): 17 | cur = power[i-1] 18 | for j in range(i): 19 | if mis[j] < mis[i]: 20 | cur += 1 21 | elif mis[j] > mis[i]: 22 | cur -= 1 23 | max_pow = max(max_pow, cur) 24 | power[i] = cur 25 | 26 | print(str(max_pow)+" "+str(power[-1])) -------------------------------------------------------------------------------- /算法笔试/VIPKID/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-03 16:55:51 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 16:56:49 7 | ''' 8 | print('%.2f'%4) -------------------------------------------------------------------------------- /算法笔试/aliyun/1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int binarySearch(int A[], int target, int n) { 3 | int low, high, mid; 4 | mid = -1; 5 | low = 0; 6 | high = n - 1; 7 | while (low <= high) { /* 这里比较重要的一点就是必须要等于,因为有可能就是其中一个数 */ 8 | mid = low + high; 9 | mid /= 2; 10 | if (target < A[mid]) 11 | high = mid - 1; 12 | else if (target > A[mid]) 13 | low = mid + 1; 14 | else 15 | break; 16 | } 17 | if (mid == -1) 18 | return 0; 19 | else 20 | return mid; 21 | } 22 | 23 | int main() { 24 | int A[] = {1, 2, 3, 5 ,10}; 25 | int c = binarySearch(A, 2, 5); 26 | } -------------------------------------------------------------------------------- /算法笔试/aliyun/2.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | 4 | struct NODE 5 | { 6 | int data; 7 | struct NODE* next; 8 | }; 9 | 10 | /* Function to get the middle of the linked list*/ 11 | void print_middle_element(struct NODE *head) 12 | { 13 | struct NODE *p1, *p2; 14 | p1->next = head; 15 | p2 = head; 16 | int tag; 17 | tag = 0; 18 | 19 | if (head == NULL) { 20 | printf("没有中间节点"); 21 | } 22 | 23 | while(p2->next != NULL) { 24 | if (p2->next->next != NULL) { /* 偶数的情况 */ 25 | p2 = p2->next->next; 26 | p1 = p1->next; 27 | } 28 | else { /* 奇数的情况 */ 29 | p2 = p2->next; 30 | p1 = p1->next; 31 | tag = 1; 32 | } 33 | } 34 | if (tag == 0) { /* 最中间的两个元素mid1和mid2 */ 35 | int mid1 = p1->data; 36 | int mid2 = p1->next->data; 37 | printf("mid1 = %d", mid1); 38 | printf("mid2 = %d", mid2); 39 | } 40 | else { /* 最中间的一个元素mid */ 41 | int mid = p1->next->data; 42 | printf("mid = %d", mid); 43 | } 44 | } 45 | 46 | int main() { 47 | struct NODE *p, *n; 48 | n = p; 49 | p->data = 0; 50 | for (int i = 0; i < 5; i++) { 51 | struct NODE *t; 52 | t->next = NULL; 53 | t->data = i + 1; 54 | p->next = t; 55 | p = t; 56 | } 57 | int data; 58 | while (n != NULL) { 59 | data = n->data; 60 | n = n->next; 61 | printf("data = %d\n", data); 62 | } 63 | } -------------------------------------------------------------------------------- /算法笔试/aliyun/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/算法笔试/aliyun/a.out -------------------------------------------------------------------------------- /算法笔试/aliyun/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Description: In User Settings Edit 3 | @Author: your name 4 | @Date: 2019-08-12 22:10:42 5 | @LastEditTime: 2019-08-14 11:33:33 6 | @LastEditors: Please set LastEditors 7 | ''' 8 | 9 | def convert(n, decimal): 10 | num = list() 11 | while n: 12 | num.append(n % decimal) 13 | n = int(n / decimal) 14 | return sum(num) 15 | 16 | result = 0 17 | for i in range(2, 3): 18 | result += convert(3, i) 19 | print(result) -------------------------------------------------------------------------------- /算法笔试/bilibili/1.py: -------------------------------------------------------------------------------- 1 | def QuickSort(list,low,high): 2 | if high > low: 3 | k = Partitions(list,low,high) 4 | QuickSort(list,low,k-1) 5 | QuickSort(list,k+1,high) 6 | 7 | def Partitions(list,low,high): 8 | left = low 9 | right = high 10 | k = list[low] 11 | while left < right : 12 | while list[left] <= k: 13 | left += 1 14 | while list[right] > k: 15 | right = right - 1 16 | if left < right: 17 | list[left],list[right] = list[right],list[left] 18 | list[low] = list[right] 19 | list[right] = k 20 | return right 21 | 22 | list_demo = [6,1,2,7,9,3,4,5,10,8] 23 | print(list_demo) 24 | QuickSort(list_demo,0,9) 25 | print(list_demo) -------------------------------------------------------------------------------- /算法笔试/bilibili/2.py: -------------------------------------------------------------------------------- 1 | class UnionFindSet(object): 2 | def __init__(self, data_list): 3 | self.father_dict = {} 4 | self.size_dict = {} 5 | 6 | for node in data_list: 7 | self.father_dict[node] = node 8 | self.size_dict[node] = 1 9 | 10 | def find_head(self, node): 11 | father = self.father_dict[node] 12 | if(node != father): 13 | father = self.find_head(father) 14 | self.father_dict[node] = father 15 | return father 16 | 17 | def is_same_set(self, node_a, node_b): 18 | return self.find_head(node_a) == self.find_head(node_b) 19 | 20 | def union(self, node_a, node_b): 21 | if node_a is None or node_b is None: 22 | return 23 | 24 | a_head = self.find_head(node_a) 25 | b_head = self.find_head(node_b) 26 | 27 | if(a_head != b_head): 28 | a_set_size = self.size_dict[a_head] 29 | b_set_size = self.size_dict[b_head] 30 | if(a_set_size >= b_set_size): 31 | self.father_dict[b_head] = a_head 32 | self.size_dict[a_head] = a_set_size + b_set_size 33 | else: 34 | self.father_dict[a_head] = b_head 35 | self.size_dict[b_head] = a_set_size + b_set_size 36 | 37 | if __name__ == '__main__': 38 | N = int(input().strip()) 39 | number = list() 40 | allList = list() 41 | for i in range(N): 42 | s = input().strip().split() 43 | a, b = int(s[0]), int(s[1]) 44 | if a not in number: 45 | number.append(a) 46 | if b not in number: 47 | number.append(b) 48 | allList.append([a, b]) 49 | 50 | union_find_set = UnionFindSet(number) 51 | for pair in (allList): 52 | a, b = pair[0], pair[1] 53 | union_find_set.union(a, b) 54 | 55 | dicA = dict() 56 | for a in number: 57 | head = union_find_set.find_head(a) 58 | if head not in dicA: 59 | dicA[head] = 0 60 | dicA[head] += 1 61 | print(dicA) -------------------------------------------------------------------------------- /算法笔试/bilibili/3.py: -------------------------------------------------------------------------------- 1 | s = input().strip().split() 2 | N, S = int(s[0]), int(s[1]) 3 | arr = [int(i) for i in input().strip().split()] 4 | if sum(arr) < S: 5 | print(-1) 6 | 7 | begin = 0 8 | end = 0 9 | maxLen = N 10 | sumNum = 0 11 | while begin < N: 12 | if end == N: 13 | break 14 | while sumNum < S and end < N: 15 | sumNum += arr[end] 16 | end += 1 17 | if maxLen > end - begin: 18 | maxLen = end - begin 19 | while sumNum > S: 20 | begin += 1 21 | sumNum -= arr[begin] 22 | print(begin, end) 23 | print(maxLen) -------------------------------------------------------------------------------- /算法笔试/bilibili/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-10 18:57:41 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-11 20:24:46 7 | ''' 8 | def maxProfit(prices): 9 | n = len(prices) 10 | if n < 2: 11 | return 0 12 | dp1 = [0 for _ in range(n)] 13 | dp2 = [0 for _ in range(n)] 14 | minval = prices[0] 15 | maxval = prices[-1] 16 | for i in range(1,n): 17 | dp1[i] = max(dp1[i-1], prices[i] - minval) 18 | minval = min(minval, prices[i]) 19 | for i in range(n-2,-1,-1): 20 | dp2[i] = max(dp2[i+1], maxval - prices[i]) 21 | maxval = max(maxval, prices[i]) 22 | 23 | dp = [dp1[i] + dp2[i] for i in range(n)] 24 | return max(dp) 25 | 26 | x = [int(x) for x in input().strip().split(' ')] 27 | print(maxProfit(x)) -------------------------------------------------------------------------------- /算法笔试/didi/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 算式转移 3 | @Author: daxiong 4 | @Date: 2019-08-27 19:44:58 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-28 09:38:18 7 | ''' 8 | # n = int(input().strip()) 9 | # strL = input().strip() 10 | n = 6 11 | strL = "3 + 2 + 1 + -4 * -5 + 1" 12 | strL = strL.split(' ') 13 | number = [int(x) for x in strL if x != '+' and x != '-' and x != '*' and x != '/'] 14 | operators = [x for x in strL if x == '+' or x == '-' or x == '*' or x == '/'] 15 | begin = 0 # 这里记录的是符号 16 | end = n -1 17 | 18 | while begin < n -1: 19 | if operators[begin] == '+': 20 | end = begin 21 | while end < n - 1 and operators[end] == '+': 22 | end += 1 23 | a = begin 24 | if begin != 0: 25 | a = begin + 1 26 | b = end 27 | if end != n - 1: 28 | b = end - 1 29 | temp = number[a: b + 1] 30 | temp.sort() 31 | for i in range(a, b + 1): 32 | number[i] = temp[i - a] 33 | begin = end 34 | elif operators[begin] == '*': # 乘法 35 | if number[begin] > number[begin + 1]: 36 | number[begin], number[begin + 1] = number[begin + 1], number[begin] 37 | begin += 1 38 | else: 39 | begin += 1 40 | 41 | for i in range(0, 2*n, 2): 42 | operators.insert(i, str(number[int(i/2)])) 43 | 44 | operators = ' '.join(operators) 45 | print(operators) 46 | 47 | # 仅仅是把加法的值全都拿出来从小到大排序,然后对于乘法就将小的数放前面,然后对于减法和除不管。是不是这样? 48 | # 最后生成的时候,我们符号的顺序是不会变的。 -------------------------------------------------------------------------------- /算法笔试/didi/1_AC.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 算式转移 3 | @Author: daxiong 4 | @Date: 2019-08-28 09:37:28 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 10:30:53 7 | ''' 8 | # n=int(input()) 9 | # s=list(input().split(" ")) 10 | s = "3 + 2 + 1 + -4 * -5 * -9 / 4 / 3 / 2 + 1 - 3 -1 -2" 11 | s = s.split() 12 | for i in range(len(s)): 13 | if s[i] in ['+','-','*','/']: 14 | new_s=s[:] 15 | for j in range(i,0,-2): # 从i这个符号往后遍历,更新 16 | if int(new_s[j + 1])>int(new_s[j - 1]): # 如果这个满足字典序,就直接返回 17 | break 18 | new_s[j + 1], new_s[j - 1] = new_s[j - 1], new_s[j + 1] # 如果前一个数比较大,就交换前后的数 19 | if eval("".join(new_s))==eval("".join(s)): # eval是用来计算表达式的值的,如果这两个值相同,就表示可以交换 20 | s=new_s[:] 21 | else: 22 | break # 如果不能交换,则s的值不变,直接继续遍历 23 | print(" ".join(s)) -------------------------------------------------------------------------------- /算法笔试/didi/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 多源D点 3 | @Author: daxiong 4 | @Date: 2019-08-27 20:37:40 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 14:28:54 7 | ''' 8 | T = input().strip().split(' ') 9 | n, m, d = int(T[0]), int(T[1]), int(T[2]) 10 | T = input().strip() 11 | limited = [int(x) for x in T.split(' ')] 12 | T = input().strip() 13 | temp = [int(x) for x in T.split(' ')] 14 | n, m, d = 6, 2, 3 15 | limited = [1, 2] 16 | temp = [3, 4, 5, 6, 1] 17 | 18 | res = list() 19 | res.append(2) 20 | while len(res) < n: 21 | x = res[-1] 22 | res.append(temp[x - 2]) 23 | 24 | for i in range(m): 25 | limited[i] = res.index(limited[i]) + 1 26 | 27 | limited.sort() 28 | if m == 1: 29 | print(min(2*d + 1, n)) 30 | if m >= 2: 31 | dis = limited[-1] - limited[0] 32 | if dis > 2 * d: 33 | print(0) 34 | else: 35 | print(min(2*d - dis + 1, n)) 36 | # 6 2 3 37 | # 2 1 38 | # 3 4 5 6 1 -------------------------------------------------------------------------------- /算法笔试/guanglianda/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 最多的整块个数 3 | @Author: daxiong 4 | @Date: 2019-08-19 15:41:02 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-19 16:02:15 7 | ''' 8 | 9 | def maxBox(n): 10 | res = 0 11 | nsqure = n ** 2 12 | 13 | for i in range(1, n): 14 | temp = nsqure - i ** 2 15 | res += int(temp ** 0.5) 16 | 17 | return res * 4 18 | 19 | print(maxBox(3)) -------------------------------------------------------------------------------- /算法笔试/guanglianda/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 最大的雨水坑 3 | @Author: daxiong 4 | @Date: 2019-08-19 15:42:49 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-19 15:56:36 7 | ''' 8 | 9 | def getMaxWater(array): 10 | left = 0 11 | right = len(array) - 1 12 | maxLeft = array[left] 13 | maxRight = array[right] 14 | maxWater = (min(maxLeft, maxRight) * (right - left)) 15 | 16 | while left < right: 17 | if maxLeft <= maxRight: 18 | while left < right and array[left] <= maxLeft: 19 | left += 1 20 | if left == right: 21 | break 22 | else: 23 | maxLeft = array[left] 24 | if (min(maxLeft, maxRight) * (right - left)) > maxWater: 25 | maxWater = (min(maxLeft, maxRight) * (right - left)) 26 | else: 27 | while right > left and array[right] <= maxRight: 28 | right -= 1 29 | if left == right: 30 | break 31 | else: 32 | maxRight = array[right] 33 | if (min(maxLeft, maxRight) * (right - left)) > maxWater: 34 | maxWater = (min(maxLeft, maxRight) * (right - left)) 35 | return maxWater 36 | 37 | array = [1, 9, 6, 2, 5, 4, 3, 10, 7] 38 | print(getMaxWater(array)) -------------------------------------------------------------------------------- /算法笔试/guanglianda/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 交换纸牌游戏 3 | @Author: daxiong 4 | @Date: 2019-08-19 15:59:14 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-01 22:29:24 7 | ''' 8 | def change(A, B): 9 | sumA = sum(A) 10 | sumB = sum(B) 11 | average = int((sumA + sumB) / 2) 12 | res = list() 13 | 14 | for num in A: 15 | if average + num - sumA in B: 16 | res.append(num) 17 | res.append(average + num - sumA) 18 | break 19 | 20 | return res 21 | 22 | A = [1, 3, 4] 23 | B = [2, 2] 24 | print(change(A, B)) -------------------------------------------------------------------------------- /算法笔试/guazi/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-26 15:02:28 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-26 15:53:48 7 | ''' 8 | import sys 9 | n = int(sys.stdin.readline().strip()) 10 | res = list(map(int,(input().strip().split(" ")))) 11 | if sorted(res, reverse = True) == res: 12 | print(0) 13 | else: 14 | maxLen = 0 15 | for begin in range(0, n - maxLen): 16 | end = n - 1 17 | while begin < end - maxLen: 18 | if res[begin] > res[end]: 19 | end -= 1 20 | else: 21 | break 22 | if end - begin > maxLen: 23 | maxLen = end - begin 24 | 25 | print(maxLen) 26 | 27 | # 双指针即可。从第一个元素开始遍历,然后从最后的一个开始往前数,找到第一个比它大的,然后比较与maxLen谁大即可。一个小的优化办法是直接在第一个遍历的时候,比较其索引与maxLen的和是否大于数组长度,如果大于就不需要再继续往下了。 28 | -------------------------------------------------------------------------------- /算法笔试/guazi/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-26 15:17:43 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-26 15:57:54 7 | ''' 8 | 9 | strL = input().strip() 10 | strL = [ord(x) for x in strL] 11 | if max(strL) <= 90 and min(strL) >= 65: # 全部大写 12 | print("true") 13 | elif strL[0] >= 65 and strL[0] <= 90 and max(strL[1:]) <= 122 and min(strL[1:]) >= 97: # 首字母大写 14 | print("true") 15 | elif min(strL) >= 97 and min(strL) <= 122: # 全部小写 16 | print("true") 17 | else: 18 | print("false") 19 | 20 | # 一个简单的思路就是全部化成数字,然后看数字的范围即可。 -------------------------------------------------------------------------------- /算法笔试/pinduoduo/1.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | import sys 3 | if __name__ == "__main__": 4 | num1 = sys.stdin.readline().strip() 5 | num2 = sys.stdin.readline().strip() 6 | num1 = list(map(int, num1.split())) 7 | num2 = list(map(int, num2.split())) 8 | 9 | index = 0 10 | num2.sort() 11 | tag = False 12 | while index < len(num1) - 1: 13 | if num1[index] > num1[index + 1]: 14 | break 15 | index += 1 16 | if index == 0: #第一个 17 | a = num1[index] 18 | b = num1[1] 19 | if len(num1) == 2: 20 | j = len(num2) - 1 21 | while j >= 0: 22 | if num2[j] > a: 23 | num1[1] = num2[j] 24 | tag = True 25 | break 26 | if num2[j] < b: 27 | num1[0] = num2[j] 28 | tag = True 29 | break 30 | j -= 1 31 | else: 32 | c = num1[2] # 这个时候需要找到比c小,然后或者比a大,或者比b小的数; 33 | j = len(num2) - 1 34 | while j >= 0: 35 | if num2[j] > a and num2[j] < c: 36 | num1[1] = num2[j] 37 | tag = True 38 | break 39 | if num2[j] < b: 40 | num1[0] = num2[j] 41 | tag = True 42 | break 43 | j -= 1 44 | elif index == len(num1) - 2: #最后一个 45 | a = num1[-2] 46 | b = num1[-1] 47 | j = len(num2) - 1 48 | while j >= 0: 49 | if num2[j] > a: 50 | num1[-1] = num2[j] 51 | tag = True 52 | break 53 | if num2[j] < b: 54 | num1[-2] = num2[j] 55 | tag = True 56 | break 57 | j -= 1 58 | else: #在中间 59 | a = num1[index-1] 60 | b = num1[index] 61 | c = num1[index+1] 62 | d = num1[index+2] 63 | j = len(num2) - 1 64 | while j >= 0: 65 | if num2[j] > b and num2[j] < d: 66 | num1[index + 1] = num2[j] 67 | tag = True 68 | break 69 | if num2[j] > a and num2[j] < c: 70 | num1[index] = num2[j] 71 | tag = True 72 | break 73 | j -= 1 74 | if tag: 75 | num1 = [str(i) for i in num1] 76 | num1 = ' '.join(num1) 77 | print(num1) 78 | else: 79 | print("NO") 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | # 然后现在需要找到的数字是需要在index-1和index+2之间的; 88 | # 其中如果a = -1,说明是第一个 89 | # 如果d = len(num1),说明是最后一个 90 | # 只有是这两种情况下,才不需要判断 91 | 92 | -------------------------------------------------------------------------------- /算法笔试/pinduoduo/2.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | import sys 3 | if __name__ == "__main__": 4 | # array = sys.stdin.readline().strip() 5 | # array = list(map(str, array.split())) 6 | res = list() 7 | array = ['CAC','CPC'] 8 | for index in range(len(array) - 1): 9 | res.append(list(set(array[index]) & set(array[index + 1]))) 10 | res.append(list(set(array[0]) & set(array[-1]))) 11 | if [] in res: 12 | print("false") 13 | if len(array) == 2: 14 | if len(res[0]) == 1 and array[0].count(res[0][0]) == 1: 15 | print('false') 16 | else: 17 | print('true') 18 | 19 | 20 | 21 | 22 | # 这题目用广度搜索试一试 -------------------------------------------------------------------------------- /算法笔试/pinduoduo/3.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | import sys 3 | if __name__ == "__main__": 4 | # line = sys.stdin.readline().strip() 5 | # N, M = map(int, line.split())[0], map(int, line.split())[1] # N,任务个数; M,依赖关系 6 | # line = sys.stdin.readline().strip() 7 | # time = map(int, line.split()) # 每个任务耗费的时间 8 | # depend = list() 9 | # for i in range(M): 10 | # line = sys.stdin.readline().strip() 11 | # depend.append(map(int, line.split())) 12 | N, M = 5, 6 13 | time = [1,2,1,1,1] 14 | depend = [[1,2],[1,3],[1,4],[2,5],[3,5],[4,5]] # 这是有依赖关系的 f 15 | depend.sort(key = lambda x:(-x[1], -x[0])) 16 | res = dict() 17 | for pair in depend: 18 | if pair[1] not in res: 19 | res[pair[1]] = list() 20 | res[pair[1]].append(pair[0]) 21 | 22 | 23 | 24 | # 首先按照依赖关系排一个顺序,然后在不改变依赖关系的条件下,将这些数组按照时间进行一个从小到大的排序; 25 | # 然后按照时间从小到大将不存在依赖关系的依次插入到数组中; 26 | 27 | 28 | -------------------------------------------------------------------------------- /算法笔试/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-31 15:01:27 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-23 18:45:34 7 | ''' 8 | 9 | -------------------------------------------------------------------------------- /算法笔试/wangyi/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-03 14:34:49 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-17 19:52:56 7 | ''' 8 | #coding=utf-8 9 | # 本题为考试多行输入输出规范示例,无需提交,不计分。 10 | import sys 11 | 12 | if __name__ == "__main__": 13 | # 读取第一行的n 14 | n = int(sys.stdin.readline().strip()) 15 | line = sys.stdin.readline().strip() 16 | values = map(int, line.split()) 17 | result = list() 18 | for v in values: 19 | result.append(n + 1 - v) 20 | result = [str(x) for x in result] 21 | print((' '.join(result))) -------------------------------------------------------------------------------- /算法笔试/wangyi/2.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | # 本题为考试多行输入输出规范示例,无需提交,不计分。 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | # 读取第一行的n 7 | # t = int(sys.stdin.readline().strip()) 8 | t = 1 9 | for i in range(t): 10 | result.sort() 11 | if nums[-1] < nums[-2] + nums[-3]: 12 | print("YES") 13 | else: 14 | print("NO") 15 | 16 | # 核心点在于先将result排序 -------------------------------------------------------------------------------- /算法笔试/wangyi/3.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | # 本题为考试多行输入输出规范示例,无需提交,不计分。 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | # 读取第一行的n 7 | n = int(sys.stdin.readline().strip()) 8 | line = sys.stdin.readline().strip() 9 | values = map(int, line.split()) 10 | result = list() 11 | for v in values: 12 | result.append(v) 13 | temp1 = [x for x in result if x % 2 == 0] 14 | temp2 = [x for x in result if x %2 != 0] 15 | if temp1 != [] or temp2 != []: 16 | result.sort() 17 | result = [str(x) for x in result] 18 | print((' '.join(result))) -------------------------------------------------------------------------------- /算法笔试/之江/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 性感素数 3 | @Author: daxiong 4 | @Date: 2019-09-02 15:05:30 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 16:45:03 7 | ''' 8 | import math 9 | 10 | def is_prime(number): 11 | if number > 1: 12 | if number == 2: 13 | return True 14 | if number % 2 == 0: 15 | return False 16 | for i in range(3, int(math.sqrt(number) + 1), 2): 17 | if number % i == 0: 18 | return False 19 | return True 20 | return False 21 | 22 | s = int(input().strip()) 23 | tag = False 24 | if is_prime(s) == True: 25 | print("YES") 26 | if is_prime(s - 6) == True: 27 | m = s - 6 28 | tag = True 29 | elif is_prime(s + 6) == True: 30 | m = s + 6 31 | tag = True 32 | if tag == True: 33 | print(m) 34 | else: 35 | print("NO") 36 | while tag == False: 37 | if is_prime(s) == True: 38 | if is_prime(s + 6) == True or is_prime(s - 6) == True: 39 | tag = True 40 | s += 1 41 | print(s - 1) 42 | -------------------------------------------------------------------------------- /算法笔试/之江/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-02 15:05:33 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 14:38:54 7 | ''' 8 | # include 9 | # include 10 | # include 11 | # include 12 | using namespace std; 13 | struct eDge{ 14 | int n1; 15 | int n2; 16 | }; 17 | int main() 18 | { 19 | int n,m,k; 20 | scanf("%d %d",&n,&m); 21 | vector v(m); 22 | for(int i = 0; i < m; i++ ) 23 | scanf("%d %d",&v[i].n1,&v[i].n2); 24 | scanf("%d",&k); 25 | while(k--){ 26 | int nodeColor[10009]; //注意需要放在while循环内,每次都需要重新利用 27 | set color; 28 | for(int i = 0; i < n; i++) { 29 | scanf("%d",&nodeColor[i]); 30 | color.insert(nodeColor[i]); 31 | } 32 | bool tag = true; 33 | for(int i = 0; i < m; i++){ 34 | if(nodeColor[v[i].n1] == nodeColor[v[i].n2]){ 35 | tag = false; 36 | break; 37 | } 38 | } 39 | if(tag) 40 | printf("%d%s\n",color.size(),"-coloring"); 41 | else 42 | printf("No\n"); 43 | } 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /算法笔试/之江/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-02 15:20:00 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-02 16:03:31 7 | ''' 8 | s = input().strip().split() 9 | n, m = int(s[0]), int(s[1]) 10 | 11 | egde = list() 12 | for i in range(m): 13 | s = input().strip().split() 14 | egde.append([int(s[0]), int(s[1])]) 15 | 16 | k = int(input().strip()) 17 | 18 | while k > 0: 19 | nodeColor = [0 for i in range(10010)] 20 | color = set() 21 | s = input().strip().split() 22 | for i in range(n): 23 | nodeColor[i] = int(s[i]) 24 | color.add(nodeColor[i]) 25 | 26 | tag = True 27 | for j in range(m): 28 | if nodeColor[egde[j][0]] == nodeColor[egde[j][1]]: 29 | tag = False 30 | break 31 | 32 | if tag == True: 33 | print("{0}-coloring".format(len(color))) 34 | else: 35 | print("No") 36 | 37 | k -= 1 -------------------------------------------------------------------------------- /算法笔试/之江2/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 验证素数 3 | @Author: daxiong 4 | @Date: 2019-09-06 15:47:53 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 16:52:49 7 | ''' 8 | 9 | def isPrime(num): 10 | if num >= 1: 11 | if num == 2: 12 | return True 13 | if num % 2 == 0: 14 | return False 15 | else: 16 | cur = 3 17 | while cur ** 2 <= num: 18 | if num % cur == 0: 19 | return False 20 | cur += 2 21 | return True 22 | return False 23 | 24 | N = int(input().strip()) 25 | 26 | a, b = 0, 0 27 | for a in range(2, int(N / 2) + 1): 28 | b = N - a 29 | if isPrime(a) == True and isPrime(b) == True: 30 | break 31 | print("{0} {1}".format(min(a, b), max(a, b))) 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /算法笔试/之江2/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 电信诈骗 3 | @Author: daxiong 4 | @Date: 2019-09-06 15:47:57 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 17:55:26 7 | ''' 8 | s = input().strip().split() 9 | K, N, M = int(s[0]), int(s[1]), int(s[2]) 10 | 11 | callMatrix = list() 12 | for i in range(N): 13 | callMatrix.append([0 for x in range(N)]) # 初始化打电话的双方 14 | 15 | for i in range(M): 16 | s = input().strip().split() 17 | caller, receiver, duration = int(s[0]), int(s[1]), int(s[2]) 18 | callMatrix[caller - 1][receiver - 1] += duration 19 | 20 | suspectList = list() 21 | 22 | for i in range(N): 23 | numOfcall = 0 # 打出的电话 24 | numOfRecall = 0 # 打回的电话 25 | for j in range(N): 26 | if callMatrix[i][j] > 0 and callMatrix[i][j] <= 5: 27 | numOfcall += 1 28 | if callMatrix[j][i] > 0: 29 | numOfRecall += 1 30 | if numOfcall > K and (float(numOfRecall) / numOfcall) <= 0.2: 31 | suspectList.append(i + 1) 32 | 33 | if len(suspectList) == 0: 34 | print("None") 35 | 36 | associates = [] # 存放对 37 | visited = [False for i in range(N)] 38 | for i in range(len(suspectList)): 39 | for j in range(i + 1, len(suspectList)): 40 | a = suspectList[i] - 1 41 | b = suspectList[j] - 1 42 | if callMatrix[a][b] > 0 and callMatrix[b][a] > 0: 43 | tag = False 44 | for i in range(len(associates)): 45 | if a in associates[i] or b in associates[i]: 46 | associates[i].add(a + 1) 47 | associates[i].add(b + 1) 48 | visited[a] = True 49 | visited[b] = True 50 | tag = True 51 | if tag == False: 52 | temp = set() 53 | temp.add(a + 1) 54 | temp.add(b + 1) 55 | visited[a] = True 56 | visited[b] = True 57 | associates.append(temp) 58 | 59 | for callPair in associates: 60 | callPair = list(callPair) 61 | callPair.sort() 62 | callPair = [str(c) for c in callPair] 63 | print(' '.join(callPair)) 64 | 65 | for i in range(len(suspectList)): 66 | if visited[suspectList[i] - 1] == False: 67 | print(suspectList[i]) -------------------------------------------------------------------------------- /算法笔试/之江2/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: Mars Numbers 3 | @Author: daxiong 4 | @Date: 2019-09-06 16:02:25 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 16:36:47 7 | ''' 8 | dicEearth2MarsA = dict() # 保存个位转换 地球文字转换火星文字 9 | dicEearth2MarsB = dict() # 保存十位转换 地球文字转换火星文字 10 | dicMars2EearthA = dict() # 保存个位转换 火星文字转换地球文字 11 | dicMars2EearthB = dict() # 保存个位转换 火星文字转换地球文字 12 | arr1 = "tret, jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" 13 | arr1 = arr1.split(',') 14 | arr2 = "tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou" 15 | arr2 = arr2.split(',') 16 | for i in range(13): 17 | dicEearth2MarsA[str(i)] = arr1[i].strip() 18 | for i in range(1, 13): 19 | dicEearth2MarsB[str(i)] = arr2[i - 1].strip() 20 | for i in range(13): 21 | dicMars2EearthA[arr1[i].strip] = i 22 | for i in range(1, 13): 23 | dicMars2EearthB[arr2[i - 1].strip] = i 24 | 25 | N = int(input().strip()) 26 | for i in range(N): 27 | s = input().strip() 28 | try: 29 | a = int(s) 30 | if a > 12: 31 | b = a % 13 # 个位转换 32 | a = int(a / 13) # 十位转换 33 | print("{0} {1}".format(dicEearth2MarsB[str(a)], dicEearth2MarsA[str(b)])) 34 | else: 35 | print(dicEearth2MarsA(str(a))) 36 | except: 37 | s = s.split() 38 | if len(s) == 1: 39 | print(dicMars2EearthA[s[0]]) 40 | else: 41 | print(dicMars2EearthB[s[1]] * 13 + dicMars2EearthA[s[0]]) 42 | 43 | 44 | -------------------------------------------------------------------------------- /算法笔试/之江2/test1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-06 16:36:59 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 16:37:00 7 | ''' 8 | -------------------------------------------------------------------------------- /算法笔试/依图/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 水源出水 3 | @Author: daxiong 4 | @Date: 2019-09-20 19:01:10 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-20 19:57:27 7 | ''' 8 | N = int(input().strip()) # 几组测试数据 9 | directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] 10 | 11 | for round in range(N): 12 | print("Case #{}:".format(round + 1)) 13 | s = input().strip().split() 14 | n, m, a, b, c = int(s[0]), int(s[1]), int(s[2]), int(s[3]), int(s[4]) 15 | 16 | matrix = [[0 for column in range(m)] for row in range(n)] 17 | visited = [[False for column in range(m)] for row in range(n)] 18 | stack = list() 19 | stack.append(([a, b], c)) 20 | matrix[a][b] = c 21 | visited[a][b] = True 22 | 23 | while stack != []: 24 | [a, b], c = stack.pop(0) 25 | for direct in directions: 26 | newA = a + direct[0] 27 | newB = b + direct[1] 28 | if 0 <= newA < n and 0 <= newB < m and visited[newA][newB] == False and c >= 1: 29 | matrix[newA][newB] = c - 1 30 | visited[newA][newB] = True 31 | stack.append(([newA, newB], c - 1)) 32 | 33 | for rows in matrix: 34 | rows = [str(val) for val in rows] 35 | print(' '.join(rows)) 36 | 37 | # n行,m列;BFS解题 -------------------------------------------------------------------------------- /算法笔试/依图/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 矩阵操作 3 | @Author: daxiong 4 | @Date: 2019-09-20 19:01:16 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-20 19:41:34 7 | ''' 8 | def multiply(matrixA, matrixB, matrixC): # 矩阵乘法操作 9 | for i in range(len(matrixC)): 10 | for j in range(len(matrixC[i])): 11 | a = 0 12 | b = 0 13 | while (a < len(matrixA[i])) and (b < len(matrixB)): 14 | matrixC[i][j] += matrixA[i][a] * matrixB[b][j] 15 | a += 1 16 | b += 1 17 | return 18 | 19 | def transpose(matrixA): # 转置操作 20 | return list(zip(*matrixA)) 21 | 22 | s = input().strip().split() 23 | n, m = int(s[0]), int(s[1]) 24 | matrixA = [[0 for column in range(m)] for row in range(n)] 25 | matrixB = [[0 for column in range(m)] for row in range(n)] 26 | 27 | for i in range(n): 28 | s = input().strip().split() 29 | s = [int(x) for x in s] 30 | matrixA[i][:] =s 31 | 32 | for i in range(n): 33 | s = input().strip().split() 34 | s = [int(x) for x in s] 35 | matrixB[i][:] = s 36 | 37 | matrixA = transpose(matrixA) # A的转置 38 | matrixC = [[0 for column in range(m)] for row in range(m)] # 第一次乘完,C为m*m 39 | multiply(matrixA, matrixB, matrixC) 40 | 41 | matrixB = transpose(matrixB) # B的转置 42 | maxtrixD = [[0 for column in range(n)] for row in range(m)] 43 | multiply(matrixC, matrixB, maxtrixD) 44 | 45 | maxtrixD = transpose(maxtrixD) # 最后的输出 46 | 47 | n_c, m_c = len(maxtrixD), len(maxtrixD[0]) 48 | print("{0} {1}".format(n_c, m_c)) 49 | 50 | for rows in maxtrixD: 51 | rows = [str((val % 1009)) for val in rows] 52 | print(' '.join(rows)) 53 | -------------------------------------------------------------------------------- /算法笔试/依图/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 计数V2.0 3 | @Author: daxiong 4 | @Date: 2019-09-20 19:01:20 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-20 22:03:01 7 | ''' 8 | T = int(input().strip()) 9 | 10 | for round in range(T): 11 | s = input().strip().split() 12 | n, m = int(s[0]), int(s[1]) 13 | points = [int(val) for val in input().strip().split()] 14 | points = [[val, index, 0] for index, val in enumerate(points)] 15 | points.sort() 16 | intervals = list() 17 | for i in range(m): 18 | s = input().strip().split() 19 | a, b = int(s[0]), int(s[1]) 20 | intervals.append([a, b]) 21 | intervals = sorted(intervals) 22 | 23 | stack = list() # 这个stack就存储的是对应这个val,第一个坐标比它小的值 24 | indexVal = 0 # 这个表示到第几个数字了 25 | indexZone = 0 # 这个表示区间取到哪个地方了 26 | 27 | while indexVal < n: 28 | val = points[indexVal][0] 29 | if indexVal == m and stack == []: 30 | break 31 | 32 | if indexZone < m and val >= intervals[indexZone][0]: 33 | while indexZone < m and val >= intervals[indexZone][0]: 34 | stack.append(intervals[indexZone]) 35 | indexZone += 1 36 | 37 | num = 0 38 | stack.sort(key = lambda x: -x[1]) 39 | curIndex = 0 40 | while curIndex < len(stack): 41 | if stack[curIndex][1] >= val: 42 | curIndex += 1 43 | num += 1 44 | curIndex += 1 45 | stack = stack[:curIndex] # 将不符合要求的全部删除 46 | 47 | points[indexVal][2] = num 48 | indexVal += 1 49 | 50 | # 如果提前结束,也即是indexVal != n - 1; 则表示后面的数全都为0,而且本来也不需要做修改 51 | print("Case #{}:".format(round + 1)) 52 | points.sort(key = lambda x: x[1]) 53 | for val in points: 54 | print(val[2]) 55 | 56 | -------------------------------------------------------------------------------- /算法笔试/依图/4.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/算法笔试/依图/4.py -------------------------------------------------------------------------------- /算法笔试/依图/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 计数V2.0 3 | @Author: daxiong 4 | @Date: 2019-09-20 20:17:18 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-20 20:20:27 7 | ''' 8 | T = int(input().strip()) 9 | 10 | for round in range(T): 11 | s = input().strip().split() 12 | n, m = int(s[0]), int(s[1]) 13 | points = [int(val) for val in input().strip().split()] 14 | intervals = list() 15 | for i in range(m): 16 | s = input().strip().split() 17 | a, b = int(s[0]), int(s[1]) 18 | intervals.append([a, b]) 19 | intervals = sorted(intervals) 20 | 21 | resNum = list() 22 | 23 | for val in points: 24 | indexZone = 0 # 这个表示区间取到哪个地方了 25 | num = 0 26 | if indexZone < m and val >= intervals[indexZone][0]: 27 | while indexZone < m and val >= intervals[indexZone][0]: 28 | if intervals[indexZone][1] >= val: 29 | num += 1 30 | indexZone += 1 31 | resNum.append(num) 32 | 33 | # 如果提前结束,也即是indexVal != n - 1; 则表示后面的数全都为0,而且本来也不需要做修改 34 | print("Case #{}:".format(round + 1)) 35 | for val in resNum: 36 | print(val) 37 | -------------------------------------------------------------------------------- /算法笔试/商汤/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 字符串分类 3 | @Author: daxiong 4 | @Date: 2019-09-21 19:11:40 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-21 19:47:08 7 | ''' 8 | N = int(input().strip()) 9 | allStr = list() 10 | 11 | for i in range(N): 12 | s = input().strip() 13 | s = list(s) 14 | s.sort() 15 | if s not in allStr: 16 | allStr.append(s) 17 | 18 | print(len(allStr)) -------------------------------------------------------------------------------- /算法笔试/商汤/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-21 19:11:44 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-21 19:52:21 7 | ''' 8 | class Solution { 9 | public: 10 | TreeNode* sortedArrayToBST(vector &nums) { 11 | if(nums.empty()) 12 | return nullptr; 13 | return recursive(nums,0,nums.size()-1); 14 | } 15 | 16 | TreeNode* recursive(vector &nums, int begin, int end){ 17 | if(begin > end) 18 | return nullptr; 19 | int mid = (begin+ end) /2; 20 | TreeNode *root = new TreeNode(nums[mid]); 21 | root->begin = recursive(nums, begin,mid -1); 22 | root->end = recursive(nums,mid+1, end); 23 | return root; 24 | } 25 | }; -------------------------------------------------------------------------------- /算法笔试/商汤/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 重复词 3 | @Author: daxiong 4 | @Date: 2019-09-21 19:11:47 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-21 20:30:44 7 | ''' 8 | class Periods: 9 | def getLongest(self, n, s): 10 | # write code here 11 | resNum = 0 12 | tag = -1 13 | for i in range(n-1, 0, -1): 14 | if i > tag and tag > 0: 15 | resNum += tag 16 | continue 17 | if tag == 0: 18 | break 19 | tag = self.isRepeat(s[:i+1]) 20 | resNum += tag 21 | return resNum 22 | 23 | def isRepeat(self, s): 24 | n = len(s) - 1 25 | for j in range(n, 0, -1): 26 | Q = s[:j] + s[:j] 27 | if Q[:len(s)] == s: 28 | return j 29 | return 0 30 | 31 | x = Periods() 32 | print(x.getLongest(8, 'babababa')) -------------------------------------------------------------------------------- /算法笔试/奇安信/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-09 19:19:52 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-10 09:51:57 7 | ''' 8 | k = int(input().strip()) 9 | s = [x for x in input().strip()] 10 | 11 | maxLen = 0 12 | begin = 0 13 | end = 0 14 | curDic = dict() 15 | 16 | while end < len(s): 17 | while len(curDic) <= k and end < len(s): 18 | if len(curDic) == k and s[end] not in curDic: 19 | break 20 | if s[end] not in curDic: 21 | curDic[s[end]] = 0 22 | curDic[s[end]] += 1 23 | end += 1 24 | if end - begin > maxLen: 25 | maxLen = end - begin 26 | while len(curDic) == k: 27 | curDic[s[begin]] -= 1 28 | if curDic[s[begin]] == 0: 29 | del curDic[s[begin]] 30 | begin += 1 31 | 32 | print(maxLen) -------------------------------------------------------------------------------- /算法笔试/小红书/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-03 18:55:33 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 20:45:02 7 | ''' 8 | strL = input().strip() 9 | 10 | stack = list() # 存放()里面的东西的 11 | curStr = '' # 这个存放最终输出的东西 12 | tag = 0 13 | for c in strL: 14 | if c == '<': 15 | if curStr != '' and tag == 0: 16 | curStr = curStr[:-1] 17 | elif c == '(': # 第一个'(' 18 | tag += 1 19 | elif c == ')': 20 | tag -= 1 21 | else: 22 | if tag == 0: 23 | curStr += c 24 | 25 | print(curStr) 26 | -------------------------------------------------------------------------------- /算法笔试/小红书/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 迷宫游戏 3 | @Author: daxiong 4 | @Date: 2019-09-03 18:55:37 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 20:46:31 7 | ''' 8 | N = int(input().strip()) 9 | matrix = list() 10 | for i in range(N): 11 | rows = list(input().strip()) 12 | if 'S' in rows: # 起始点 13 | begin = [i, rows.index('S')] 14 | if 'E' in rows: # 结束点 15 | end = [i, rows.index('E')] 16 | rows[rows.index('E')] = '.' 17 | matrix.append(rows) 18 | 19 | visited = [[False for _ in a] for a in matrix] 20 | stack = list() 21 | stack.append((begin, 0)) 22 | 23 | find = False 24 | while stack != []: 25 | [a, b], depth = stack.pop(0) 26 | if [a, b] == end: 27 | find = True 28 | break 29 | if matrix[(a - 1 + N) % N][b] == '.' and visited[(a - 1 + N) % N][b] == False: # 向左移 30 | stack.append(([(a - 1 + N) % N, b], depth + 1)) 31 | visited[(a - 1 + N) % N][b] = True 32 | 33 | if matrix[(a + 1 + N) % N][b] == '.' and visited[(a + 1 + N) % N][b] == False: # 向右移 34 | stack.append(([(a + 1 + N) % N, b], depth + 1)) 35 | visited[(a + 1 + N) % N][b] = True 36 | 37 | if matrix[a][(b - 1 + N) % N] == '.' and visited[a][(b - 1 + N) % N] == False: # 向上移 38 | stack.append(([a, (b - 1 + N) % N], depth + 1)) 39 | visited[a][(b - 1 + N) % N] = True 40 | 41 | if matrix[a][(b + 1 + N) % N] == '.' and visited[a][(b + 1 + N) % N] == False: # 向上移 42 | stack.append(([a, (b + 1 + N) % N], depth + 1)) 43 | visited[a][(b + 1 + N) % N] = True 44 | 45 | if find == True: 46 | print(depth) 47 | else: 48 | print(-1) 49 | 50 | # 注意设置visited数组 51 | # 在BFS的时候用深度来表示 -------------------------------------------------------------------------------- /算法笔试/小红书/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-03 20:49:46 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 20:56:27 7 | ''' 8 | N = int(input().strip()) 9 | arr = list() 10 | for i in range(N): 11 | s = input().strip().split() 12 | arr.append((int(s[0]), int(s[1]))) 13 | 14 | arr.sort(key=lambda x: (x[0], x[1])) 15 | resNum = 1 16 | print(arr) 17 | a, b = arr[0][0], arr[0][1] 18 | for i in range(1, N): 19 | if arr[i][0] >= a and arr[i][1] >= b: 20 | resNum += 1 21 | a = arr[i][0] 22 | b = arr[i][1] 23 | 24 | print(resNum) -------------------------------------------------------------------------------- /算法笔试/思科/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 解析数据 3 | @Author: daxiong 4 | @Date: 2019-09-23 18:45:57 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-23 20:00:12 7 | ''' 8 | s = input().strip() 9 | tag = True 10 | if s[-1] == '"': 11 | s = s[1: -1] 12 | else: 13 | s = s[1: ] 14 | tag = False 15 | 16 | s = s[::-1] 17 | if tag == False: 18 | s = s[s.index('<') + 2: ] 19 | else: 20 | s = s[s.index('<') + 1: ] 21 | s = s[::-1] 22 | if s[ :3] == "%22" and s[-3: ] == "%22": 23 | s = s[3: -3] 24 | print(s) -------------------------------------------------------------------------------- /算法笔试/思科/2.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/算法笔试/思科/2.py -------------------------------------------------------------------------------- /算法笔试/思科/3.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/算法笔试/思科/3.py -------------------------------------------------------------------------------- /算法笔试/招商银行/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 小招喵的机器人 3 | @Author: daxiong 4 | @Date: 2019-09-15 21:10:43 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-15 21:49:33 7 | ''' 8 | strL = input().strip() 9 | lenth = len(strL) 10 | resList = [str(0) for x in strL] 11 | 12 | begin = 0 # 起始点 一定是R 13 | end = 0 # 结束点 一定是L 14 | Rpositions = 0 # R的位置 15 | Lpositions = 0 # L的位置 16 | 17 | index = 0 18 | while index < lenth: 19 | numR = 0 20 | numL = 0 21 | begin = index 22 | while strL[index] == 'R': 23 | index += 1 24 | Rpositions = index - 1 25 | Lpositions = index 26 | while index < lenth and strL[index] == 'L': 27 | index += 1 28 | end = index - 1 29 | # print(begin, Rpositions, Lpositions, end) 30 | numR = int((Rpositions - begin) / 2) + int((end - Rpositions) / 2) + 1 31 | numL = int((Lpositions - begin) / 2) + int((end - Lpositions) / 2)+ 1 32 | resList[Rpositions] = str(numR) 33 | resList[Lpositions] = str(numL) 34 | # print(numR, numL) 35 | 36 | print(' '.join(resList)) -------------------------------------------------------------------------------- /算法笔试/招商银行/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-15 20:30:15 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-15 22:22:35 7 | ''' 8 | strL = input().strip() 9 | strL = strL[::-1] 10 | 11 | resNum = 0 12 | dp = [[0 for i in range(10)] for j in range(len(strL))] 13 | 14 | for i in range(len(strL)): 15 | if strL[i] == '?': 16 | for j in range(10): 17 | if i == 0: 18 | dp[0][j] = (j + 8) % 13 19 | else: 20 | dp[i][j] = (dp[i - 1][j] + j * 10 +8 ) % 13 21 | else: 22 | c = int(strL[i]) 23 | for j in range(10): 24 | dp[i][j] = (dp[i - 1][j] + c * 10 + 8) % 13 25 | 26 | print(dp) 27 | 28 | 29 | # 2?? -------------------------------------------------------------------------------- /算法笔试/招商银行/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-15 20:30:18 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-15 22:42:51 7 | ''' 8 | n = input() 9 | ans = [1]* len(n) 10 | if len(n) == 2: 11 | print('1 1') 12 | else: 13 | for i in range(1, len(n)-1): 14 | if n[i] == 'R' and n[i-1] == 'R': 15 | ans[i+1] += ans[i-1] 16 | ans[i-1] = 0 17 | for j in range(len(n)-2, 0, -1): 18 | if n[j] == 'L' and n[j+1] == 'L': 19 | ans[j-1] += ans[j+1] 20 | ans[j+1] = 0 21 | print(' '.join(str(i) for i in ans)) -------------------------------------------------------------------------------- /算法笔试/招商银行/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 小招喵的机器人 3 | @Author: daxiong 4 | @Date: 2019-09-15 21:10:43 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-15 22:30:30 7 | ''' -------------------------------------------------------------------------------- /算法笔试/招行/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-24 15:58:11 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-24 16:29:28 7 | ''' 8 | N = int(raw_input().strip()) 9 | # N = 10 10 | S = N - 2 11 | matrix = [[' ' for i in range(4*S-2)] for _ in range(N)] 12 | 13 | 14 | for i in range(S): 15 | if i == 0: 16 | matrix[i][S-1] = '*' 17 | matrix[i][3*S-2] = '*' 18 | elif i == 1: 19 | x = [S - 2, 3*S-3] 20 | for j in x: 21 | for k in range(3): 22 | matrix[i][j + k] = '*' 23 | else: 24 | x = [S - i - 1, S + i - 2, 3*S - i-2, 3*S + i - 3] 25 | for j in x: 26 | for k in range(2): 27 | matrix[i][j + k] = '*' 28 | 29 | matrix[S][:] = ['*' for i in range((4*S-2))] 30 | matrix[S+1][1:-1] = ['*' for i in range((4*S-4))] 31 | for row in matrix: 32 | print(''.join(row)) 33 | 34 | 35 | -------------------------------------------------------------------------------- /算法笔试/招行/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-24 15:58:15 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-24 16:41:49 7 | ''' 8 | s = raw_input().strip().split(',') 9 | s = [int(x) for x in s ] 10 | 11 | visited = [False for val in range(len(s))] 12 | resNum = 0 13 | for i in range(len(s)): 14 | if s[i] == 1: 15 | visited[i] = True 16 | if i -1 >= 0 and s[i - 1] == 0: 17 | visited[i - 1] = True 18 | if i + 1 < len(s) and s[i + 1] == 0: 19 | visited[i + 1] = True 20 | if s[i] == 2: 21 | visited[i] = True 22 | if i - 1 >= 0 and s[i - 1] == 0: 23 | visited[i - 1] = True 24 | if i - 2 >= 0 and s[i - 2] == 0: 25 | visited[i - 2] = True 26 | if i + 1 < len(s) and s[i + 1] == 0: 27 | visited[i + 1] = True 28 | if i + 2 < len(s) and s[i + 2] == 0: 29 | visited[i + 2] = True 30 | 31 | for i in range(len(s)): 32 | if visited[i] == True: 33 | continue 34 | else: 35 | visited[i] = True 36 | if i + 1 < len(s) and s[i + 1] == 0: 37 | visited[i + 1] = True 38 | resNum += 1 39 | 40 | print(resNum) -------------------------------------------------------------------------------- /算法笔试/拼多多_2/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 优先偶数TopN序 3 | @Author: daxiong 4 | @Date: 2019-09-01 14:54:37 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-01 15:12:29 7 | ''' 8 | s = input().strip().split(',') 9 | s[-1], N = s[-1].split(';')[0], int(s[-1].split(';')[1]) 10 | a = [int(x) for x in s if int(x) % 2 == 0] 11 | b = [int(x) for x in s if int(x) % 2 != 0] 12 | a.sort(reverse = True) 13 | b.sort(reverse = True) 14 | resList = list() 15 | if len(a) >= N: 16 | resList = a[: N] 17 | else: 18 | resList = a + b[: N - len(a)] 19 | 20 | resList = [str(x) for x in resList] 21 | print(','.join(resList)) -------------------------------------------------------------------------------- /算法笔试/拼多多_2/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 扑克游戏 3 | @Author: daxiong 4 | @Date: 2019-09-01 14:54:41 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 15:34:12 7 | ''' 8 | round = int(input().strip()) # 存储轮数 9 | 10 | nList = list() # 存储小梅的序列 11 | mList = list() # 存储小白的序列 12 | for i in range(round): 13 | s = input().strip() 14 | nTemp = [int(x) for x in s] 15 | nList.append(nTemp) 16 | 17 | s = input().strip() 18 | mTemp = [int(x) for x in s] 19 | mList.append(mTemp) 20 | 21 | allops = [] 22 | 23 | def dfs(nArray, newArray, mArray, operators): 24 | if newArray == mArray: 25 | if operators not in allops: 26 | allops.append(operators) 27 | return 28 | for i in range(len(nArray)): 29 | dfs(nArray[1: ], newArray, mArray, operators + ['d']) 30 | dfs(nArray[1: ], [nArray[0]] + newArray, mArray, operators + ['l']) 31 | dfs(nArray[1: ], newArray + [nArray[0]], mArray, operators + ['r']) 32 | 33 | 34 | for i in range(round): 35 | nArray = nList[i] 36 | mArray = mList[i] 37 | N = len(nArray) 38 | M = len(mArray) 39 | 40 | print("{") 41 | dfs(nArray, [], mArray, []) 42 | allops.sort() 43 | for op in allops: 44 | op = ' '.join(op) 45 | print(op) 46 | print("}") 47 | allops = [] -------------------------------------------------------------------------------- /算法笔试/拼多多_2/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-01 14:54:45 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-01 14:54:45 7 | ''' 8 | -------------------------------------------------------------------------------- /算法笔试/拼多多_2/4.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-01 14:54:47 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-01 17:05:49 7 | ''' 8 | s = input().strip().split() 9 | n, m, k = int(s[0]), int(s[1]), int(s[2]) 10 | # d = k 11 | 12 | m, n, k = 5, 3, 5 13 | d = k 14 | 15 | stack = list() 16 | stack.append([m*n, m, n]) # 最大值 17 | k -= 1 18 | cur = 0 19 | visited = list() 20 | visited.append([m, n]) 21 | 22 | while k > 0: 23 | stack.sort(reverse = True) 24 | s = stack.pop(0) 25 | cur += 1 26 | a ,b = s[1], s[2] 27 | if a - 1 >= 1 and [a-1, b] not in visited: 28 | stack.append([(a-1)*b, a - 1, b]) 29 | visited.append([a-1, b]) 30 | k -= 1 31 | if b -1 >= 1 and [a, b-1] not in visited: 32 | stack.append([(b-1)*a, a, b - 1]) 33 | visited.append([a, b-1]) 34 | k -= 1 35 | stack.sort(reverse = True) 36 | print(stack[d - cur - 1][0]) 37 | 38 | 39 | -------------------------------------------------------------------------------- /算法笔试/携程/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttionl 车辆时刻表分组 3 | @Author: daxiong 4 | @Date: 2019-09-04 19:13:54 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-04 19:50:04 7 | ''' 8 | strL = input().strip() 9 | numList = list() # 存放每一组的值 10 | limited = dict() # 存放是否符合条件 11 | curLength = 0 12 | 13 | for c in strL: 14 | if c in limited: 15 | limited[c] -= 1 16 | if limited[c] == 0: 17 | del limited[c] 18 | if limited == dict(): 19 | numList.append(curLength + 1) 20 | curLength = 0 21 | else: 22 | curLength += 1 23 | else: 24 | limited[c] = strL.count(c) - 1 25 | if limited[c] == 0: 26 | del limited[c] 27 | if limited == dict(): 28 | numList.append(curLength + 1) 29 | curLength = 0 30 | else: 31 | curLength += 1 32 | numList = [str(x) for x in numList] 33 | print(','.join(numList)) 34 | 35 | # 也即出现在这个组的数据c,所有c都必须放在这一组里面 -------------------------------------------------------------------------------- /算法笔试/携程/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: AUC计算 3 | @Author: daxiong 4 | @Date: 2019-09-04 19:58:23 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-04 20:09:16 7 | ''' 8 | N = int(input().strip()) 9 | prob = list() 10 | labels = list() 11 | 12 | for i in range(N): 13 | s = input().strip().split() 14 | labels.append(int(s[0])) 15 | prob.append(float(s[1])) 16 | 17 | combine = list(zip(prob, labels)) 18 | rank = [x2 for x1, x2 in sorted(combine, key=lambda x: x[0])] 19 | rankList = [i + 1 for i in range(len(rank)) if rank[i] == 1] 20 | posNum = 0 21 | negNum = 0 22 | for i in range(len(labels)): 23 | if labels[i] == 1: 24 | posNum += 1 25 | else: 26 | negNum += 1 27 | auc = (sum(rankList) - (posNum * (posNum + 1)) / 2) / (posNum * negNum) 28 | print(auc) 29 | -------------------------------------------------------------------------------- /算法笔试/携程/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 旅游路线设计 3 | @Author: daxiong 4 | @Date: 2019-09-04 20:16:30 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-04 20:51:54 7 | ''' 8 | 9 | N = int(input().strip()) # 顶点数 10 | M = int(input().strip()) # 通道数 11 | 12 | inf = 100000000 13 | dis = list() 14 | minds = list() 15 | 16 | for i in range(N + 1): 17 | dis.append([inf for x in range(N + 1)]) 18 | minds.append([0 for x in range(N + 1)]) 19 | 20 | for i in range(M): 21 | s = input().strip().split() 22 | a, b, t = int(s[0]), int(s[1]), int(s[2]) 23 | if dis[a][b] > t: 24 | dis[a][b] = t 25 | dis[b][a] = t 26 | 27 | for i in range(1, N + 1): 28 | for j in range(1, N + 1): 29 | minds[i][j] = dis[i][j] 30 | 31 | ansids = inf 32 | anscnt = 0 33 | 34 | for k in range(1, N + 1): 35 | for i in range(1, k): 36 | for j in range(i + 1, k): 37 | if ansids > dis[i][k] + dis[j][k] + minds[i][j]: 38 | ansids = dis[i][k] + dis[j][k] + minds[i][j] 39 | ansids = dis[i][k] + dis[j][k] + minds[i][j] 40 | elif ansids == dis[i][k] + dis[j][k] + minds[i][j]: 41 | anscnt += dis[i][k] + dis[j][k] + minds[i][j] 42 | 43 | for i in range(1, N + 1): 44 | for j in range(1, N + 1): 45 | minds[i][j] = min(minds[i][j], minds[i][k] + minds[j][k]) 46 | 47 | if anscnt == 0: 48 | print(-1) 49 | else: 50 | print(anscnt) 51 | -------------------------------------------------------------------------------- /算法笔试/携程/test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Descripttion: 3 | * @Author: daxiong 4 | * @Date: 2019-09-04 19:58:49 5 | * @LastEditors: daxiong 6 | * @LastEditTime: 2019-09-04 20:34:29 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #define inf 100000000 13 | using namespace std; 14 | 15 | int dis[110][110]; 16 | int mindis[110][110]; 17 | 18 | int main() { 19 | int t; 20 | cin >> t; 21 | while(t--) { 22 | int n, m; 23 | cin >> n >> m; 24 | 25 | for (int i=1; i<=n; ++i) { 26 | for (int j=1; j<=n; ++j) { 27 | dis[i][j] = inf; 28 | } 29 | } 30 | 31 | for (int i=0; i> x >> y >> w; 34 | if (dis[x][y] > w) { 35 | dis[x][y] = w; 36 | dis[y][x] = w; 37 | } 38 | } 39 | 40 | for (int i=1; i<=n; ++i) { 41 | for (int j=1; j<=n; ++j) { 42 | mindis[i][j] = dis[i][j]; 43 | } 44 | } 45 | 46 | int ansdis = inf, anscnt = 0; 47 | 48 | for (int k=1; k<=n; ++k) { 49 | for (int i=1; i dis[i][k] + dis[j][k] + mindis[i][j]) { 52 | ansdis = dis[i][k] + dis[j][k] + mindis[i][j]; 53 | anscnt = 1; 54 | } 55 | else if (ansdis == dis[i][k] + dis[j][k] + mindis[i][j]) { 56 | anscnt++; 57 | } 58 | } 59 | } 60 | for (int i=1; i<=n; ++i) { 61 | for (int j=1; j<=n; ++j) { 62 | mindis[i][j] = min(mindis[i][j], mindis[i][k] + mindis[j][k]); 63 | } 64 | } 65 | } 66 | 67 | if (anscnt == 0) { 68 | cout << "-1\n"; 69 | } 70 | else cout << ansdis << " " << anscnt << endl; 71 | } 72 | return 0; 73 | } -------------------------------------------------------------------------------- /算法笔试/新浪/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 算法开发 3 | @Author: daxiong 4 | @Date: 2019-08-31 15:56:23 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-31 17:00:43 7 | ''' 8 | # s = input().strip().split(',') 9 | # s = [int(x) for x in s] 10 | s = [1, 2, 3, 4, 5] 11 | s.sort() 12 | resNum = 0 13 | end = len(s) - 1 14 | begin = 0 15 | while end > begin: 16 | if end > begin and s[end] > s[begin] + end - begin: 17 | end -= 1 18 | else: 19 | break 20 | temp = [s[begin] + i + 1 for i in range(end - begin)] 21 | resNum = sum(temp) - sum(s[begin + 1: end + 1]) 22 | print(resNum) -------------------------------------------------------------------------------- /算法笔试/流利说/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-11 21:04:38 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-12 09:17:50 7 | ''' 8 | import sys 9 | line = sys.stdin.readline().strip() 10 | while line: 11 | line = line.replace('[', '').replace(']', '') 12 | line = [int(x) for x in line.split(',')] 13 | N = int(len(line) ** 0.5) 14 | print(N) 15 | 16 | line = sys.stdin.readline().strip() 17 | 18 | 19 | # [[0, 1, 0], [0, 0, 1], [1, 0, 0]] 20 | # [[0, 0, 0, 1, 0], [1, 0, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 1, 0, 0, 0]] -------------------------------------------------------------------------------- /算法笔试/流利说/test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * @Descripttion: 3 | * @Author: daxiong 4 | * @Date: 2019-09-11 21:45:22 5 | * @LastEditors: daxiong 6 | * @LastEditTime: 2019-09-11 21:45:22 7 | */ 8 | import java.util.Scanner; 9 | 10 | public class test2 { 11 | //邻接矩阵 12 | static int[][] graph = new int[200][200]; 13 | //结点个数和边的个数 14 | static int vNum,eNum; 15 | //标记矩阵,0为当前结点未访问,1为访问过,-1表示当前结点后边的结点都被访问过。 16 | static int[] color = new int[200]; 17 | //是否是DAG(有向无环图) 18 | static boolean isDAG = true; 19 | 20 | //图的深度遍历函数 21 | void DFS(int i){ 22 | System.out.println("正在访问结点"+i); 23 | //结点i变为访问过的状态 24 | color[i] = 1; 25 | for(int j=1;j<=vNum;j++){ 26 | //如果当前结点有指向的结点 27 | if(graph[i][j] != 0){ 28 | //并且已经被访问过 29 | if(color[j] == 1){ 30 | isDAG = false;//有环 31 | break; 32 | }else if(color[j] == -1){ 33 | //当前结点后边的结点都被访问过,直接跳至下一个结点 34 | continue; 35 | }else{ 36 | DFS(j);//否则递归访问 37 | } 38 | } 39 | } 40 | //遍历过所有相连的结点后,把本节点标记为-1 41 | color[i] = -1; 42 | } 43 | 44 | //创建图,以邻接矩阵表示 45 | void create(){ 46 | Scanner sc = new Scanner(System.in); 47 | System.out.println("正在创建图,请输入顶点个数vNum:"); 48 | vNum = sc.nextInt(); 49 | System.out.println("请输入边个数eNum:"); 50 | eNum = sc.nextInt(); 51 | //初始化邻接矩阵为0(如果3个顶点,顶点分别是1,2,3) 52 | for(int i=1;i<=vNum;i++){ 53 | for(int j=1;j<=vNum;j++){ 54 | graph[i][j] = 0; 55 | } 56 | } 57 | for(int k=1;k<=eNum;k++){ 58 | int i = sc.nextInt(); 59 | int j = sc.nextInt(); 60 | graph[i][j] = 1; 61 | } 62 | for(int i=1;i<=vNum;i++){ 63 | color[i] = 0; 64 | } 65 | } 66 | 67 | public static void main(String[] args) { 68 | test2 t = new test2(); 69 | t.create(); 70 | for(int i=1;i<=vNum;i++){ 71 | if(color[i] == -1){ 72 | continue; 73 | } 74 | t.DFS(i); 75 | if(!isDAG){ 76 | System.out.println("1"); 77 | break; 78 | } 79 | } 80 | if(isDAG){ 81 | System.out.println("0"); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /算法笔试/百度/1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/算法笔试/百度/1.py -------------------------------------------------------------------------------- /算法笔试/百度/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-17 20:09:57 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-17 21:14:43 7 | ''' 8 | s = input().strip().split() 9 | a1, a2, a3, a4, N = int(s[0]), int(s[1]), int(s[2]), int(s[3]), int(s[4]) 10 | 11 | const = 10**9 + 7 12 | arr = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] 13 | index = 5 14 | while index <= N: 15 | for j in range(4): 16 | a = ((index - 1) % 4 + 3) % 4 17 | b = ((index - 3) % 4 + 3) % 4 18 | c = ((index - 4) % 4 + 3) % 4 19 | x = (index % 4 + 3) % 4 20 | arr[x][j] = arr[a][j] + arr[b][j] + arr[c][j] 21 | 22 | index += 1 23 | resNum = a1 * arr[x][0] + a2 * arr[x][1] + a3 * arr[x][2] + a4 * arr[x][3] 24 | print(resNum%const) -------------------------------------------------------------------------------- /算法笔试/网易互娱/1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/算法笔试/网易互娱/1.py -------------------------------------------------------------------------------- /算法笔试/腾讯2/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 消消乐 3 | @Author: daxiong 4 | @Date: 2019-09-01 20:00:21 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-01 20:22:49 7 | ''' 8 | T = int(input().strip()) 9 | 10 | for i in range(T): 11 | n = int(input().strip()) 12 | arr = input().strip().split() 13 | arr = [int(x) for x in arr] 14 | nums = list() 15 | for c in set(arr): 16 | nums.append(arr.count(c)) 17 | nums.sort() 18 | while nums != [] and len(nums) != 1: 19 | nums[-2] -= 1 20 | nums[-1] -= 1 21 | if nums[-1] == 0: 22 | nums.pop(-1) # 这个时候最后两个肯定都为1 23 | nums.pop(-1) 24 | if len(nums) >= 2 and nums[-2] == 0: 25 | nums.pop(-2) 26 | nums.sort() 27 | 28 | if nums == []: 29 | print("YES") 30 | else: 31 | print("NO") 32 | -------------------------------------------------------------------------------- /算法笔试/腾讯2/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 花匠小Q 3 | @Author: daxiong 4 | @Date: 2019-09-01 20:28:08 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-01 22:19:41 7 | ''' 8 | # s = input().strip().split() 9 | # t, k = int(s[0]), int(s[1]) 10 | t = 1 11 | k = 2 12 | 13 | 14 | def getValue(n): 15 | if n <= 1: 16 | return 1 17 | else: 18 | return n*getValue(n-1) 19 | 20 | def getC(n, m): 21 | first = getValue(n) 22 | second = getValue(m) 23 | third = getValue(n - m) 24 | return int(first/(second*third)) 25 | 26 | 27 | for i in range(t): 28 | # s = input().strip().split() 29 | # a, b = int(s[0]), int(s[1]) 30 | 31 | a, b = 3,3 32 | 33 | resNum = 0 34 | for flower in range(a, b + 1): # 摆flower朵花 35 | c = int(flower / k) # 表示最多有这么多组白花; 36 | for j in range(c + 1): 37 | resNum += getC(flower-j*k+j, j) 38 | 39 | print(resNum) 40 | 41 | 42 | -------------------------------------------------------------------------------- /算法笔试/腾讯3/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 柠檬的选择 3 | @Author: daxiong 4 | @Date: 2019-09-20 20:38:01 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-20 20:53:07 7 | ''' 8 | s = input().strip().split() 9 | n, m = int(s[0]), int(s[1]) 10 | 11 | lemonA = [int(x) for x in input().strip().split()] 12 | lemonB = [int(x) for x in input().strip().split()] 13 | lemonA.sort() 14 | lemonB.sort() 15 | 16 | a, b, c, d = lemonA[0],lemonA[1], lemonA[-2], lemonA[-1] 17 | m, n = lemonB[0], lemonB[-1] 18 | maxAB = max(a*m, a*n, d*m, d*n) 19 | if a*m == maxAB or a*n == maxAB: # 这种情况去掉a 20 | print(max(b*m, b*n, d*m, d*n)) 21 | else: #这种情况去掉a 22 | print(max(a*m, a*n, c*m, c*n)) 23 | -------------------------------------------------------------------------------- /算法笔试/腾讯3/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 数轴游戏 3 | @Author: daxiong 4 | @Date: 2019-09-20 20:38:04 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-20 21:26:10 7 | ''' 8 | n = int(input().strip()) 9 | arr = [int(x) for x in input().strip().split()] 10 | arr.sort() 11 | 12 | resNum = 0 13 | for i in range(len(arr) - 1): 14 | for j in range(i + 1, len(arr)): 15 | if abs(arr[i]) *2 >= abs(arr[j]) or abs(arr[i]) <= abs(arr[j]) * 2: 16 | resNum += 1 17 | 18 | print(resNum) -------------------------------------------------------------------------------- /算法笔试/腾讯3/3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-20 20:38:07 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-20 21:38:22 7 | ''' 8 | s = input().strip().split() 9 | n, k = int(s[0]), int(s[1]) 10 | 11 | arr = list() 12 | for i in range(n): 13 | s = input().strip().split() 14 | a, b = int(s[0]), int(s[1]) 15 | arr.append([a, b]) 16 | 17 | arr.sort(reverse = True) 18 | resNum = 0 19 | Kval = 0 20 | minK = arr[k-1][0] 21 | minVal = arr[0][1] 22 | for i in range(k): 23 | Kval += arr[i][0] 24 | if arr[i][1] < minVal: 25 | minVal = arr[i][1] 26 | 27 | resNum = minVal * Kval 28 | for i in range(k, n): 29 | if (Kval - minK + arr[i][0]) * min(arr[i][1], minVal) > resNum: 30 | resNum = (Kval - minK + arr[i][0]) * min(arr[i][1], minVal) 31 | print(resNum) 32 | -------------------------------------------------------------------------------- /算法笔试/英特尔/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-03 18:55:05 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 18:55:19 7 | ''' 8 | -------------------------------------------------------------------------------- /算法笔试/英特尔/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-03 18:55:10 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-03 18:55:11 7 | ''' 8 | -------------------------------------------------------------------------------- /算法笔试/途宿/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 寻找最大数 3 | @Author: daxiong 4 | @Date: 2019-09-06 20:31:58 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 20:41:30 7 | ''' 8 | s = input().strip().split() 9 | strL = [int(x) for x in s[0]] 10 | m = int(s[1]) 11 | newLength = len(strL) - m 12 | newNum = '' 13 | 14 | while newLength != 0: # 一个一个的找到最大的数字 15 | maxNum = max(strL[: len(strL) - newLength + 1]) 16 | newNum += str(maxNum) 17 | strL = strL[strL.index(maxNum) + 1: ] 18 | newLength -= 1 19 | 20 | print(newNum) -------------------------------------------------------------------------------- /算法笔试/途宿/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 0,1背包问题 3 | @Author: daxiong 4 | @Date: 2019-09-06 20:32:01 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 20:49:42 7 | ''' 8 | s = input().strip().split() 9 | n, m = int(s[0]), int(s[1]) 10 | packet = list() 11 | 12 | for i in range(n): 13 | s = input().strip().split() 14 | w, v = int(s[0]), int(s[1]) 15 | packet.append((float(v) / w, v, w)) 16 | 17 | packet.sort(key = lambda x: -x[0]) # 按照性价比排序 18 | 19 | resValue = 0 20 | for c in packet: 21 | v, w = c[1], c[2] 22 | if w > m: 23 | break 24 | else: 25 | resValue += v 26 | m -= w 27 | print(resValue) 28 | -------------------------------------------------------------------------------- /算法笔试/途宿/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: ASCII排序 3 | @Author: daxiong 4 | @Date: 2019-09-06 21:20:36 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-06 21:25:55 7 | ''' 8 | s = input().strip() 9 | visited = [False for _ in range(len(s))] 10 | strC = list() 11 | 12 | for i in range(len(s)): 13 | if s[i].isalpha(): 14 | strC.append(s[i]) 15 | visited[i] = True 16 | 17 | s = list(s) 18 | strC.sort(reverse = True) 19 | for i in range(len(s)): 20 | if visited[i] == True: 21 | s[i] = strC.pop(-1) 22 | 23 | print(''.join(s)) 24 | -------------------------------------------------------------------------------- /算法笔试/银行/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-09-19 16:59:42 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-19 17:50:38 7 | ''' 8 | N = int(input().strip()) 9 | resNum = 1 10 | while N / 2 != 0: 11 | resNum += 1 12 | N = int(N / 2) 13 | print(N) 14 | 15 | def factorial(n): 16 | result = n; 17 | for i in range(1,n): 18 | result *= i 19 | if result > 1000003: 20 | result %= 1000003 21 | return result 22 | 23 | print(factorial(resNum)) -------------------------------------------------------------------------------- /算法笔试/银行/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 香蕉问题 3 | @Author: daxiong 4 | @Date: 2019-09-19 19:08:21 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-09-19 19:20:17 7 | ''' 8 | def getNumOfBananas(num, rounds): 9 | print(num) 10 | if rounds == 5: 11 | return num 12 | else: 13 | num = num * 5 + 1 14 | return getNumOfBananas(num, rounds + 1) 15 | 16 | print(getNumOfBananas(1, 1)) 17 | -------------------------------------------------------------------------------- /算法笔试/阿里/1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/算法笔试/阿里/1.py -------------------------------------------------------------------------------- /算法笔试/阿里/2.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | ''' 3 | @Descripttion: 任务题 4 | @Author: daxiong 5 | @Date: 2019-08-30 19:57:46 6 | @LastEditors: daxiong 7 | @LastEditTime: 2019-08-30 20:34:59 8 | ''' 9 | import itertools 10 | # limited = int(input()) 11 | # minNum = int(input()) 12 | # maxNum = int(input()) 13 | # strA = raw_input().strip().split(',') 14 | # strB = raw_input().strip().split(',') 15 | 16 | limited = 1 17 | minNum = 3 18 | maxNum = 5 19 | strA = ['weather', 'joke', 'music', 'stock', 'joke', 'news', 'taxi', 'temperature', 'pm2.5'] 20 | strB = ['joke', 'music', 'news', 'stock', 'joke', 'joke', 'news', 'taxi'] 21 | 22 | allA = list(itertools.permutations(strA)) 23 | print(allA) 24 | 25 | def cut2(s, minNum, maxNum): 26 | results = [] 27 | 28 | # x + 1 表示子字符串长度 29 | for x in range(minNum, maxNum + 1): 30 | # i 表示偏移量 31 | for i in range(len(s) - x): 32 | if x == 0: 33 | results.append(s[i:i + x + 1]) 34 | elif x < 2: 35 | for j in range(len(s) - x - i): 36 | results.append(s[i] + s[j + x + i]) 37 | else: 38 | for j in range(len(s) - x - i): 39 | results.append(s[i:i+x] + s[j + x + i]) 40 | 41 | print(cut2(strA, minNum, maxNum)) 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /算法笔试/顺丰/1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-29 18:46:02 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-29 21:02:56 7 | ''' 8 | def union_find(nodes, edges): 9 | father = [0]*len(nodes) # 记录父节点 10 | for node in nodes: # 初始化为本身 11 | father[node] = node 12 | 13 | for edge in edges: # 标记父节点 14 | head = edge[0] 15 | tail = edge[1] 16 | father[tail] = head 17 | 18 | for node in nodes: 19 | while True: # 循环,直到找到根节点 20 | father_of_node = father[node] 21 | if father_of_node != father[father_of_node]: 22 | father[node] = father[father_of_node] 23 | else: # 如果该节点的父节点与其爷爷节点相同, 24 | break # 则说明找到了根节点 25 | 26 | L = {} 27 | for i, f in enumerate(father): 28 | L[f] = [] 29 | for i, f in enumerate(father): 30 | L[f].append(i) 31 | 32 | s = input().split() 33 | n, m, k = int(s[0]), int(s[1]), int(s[2]) 34 | data = list() 35 | for i in range(k): 36 | s = input().split() 37 | data.append([int(s[0]), int(s[1])]) 38 | 39 | L = union_find(list(range(0, n)), data) 40 | print(L) 41 | -------------------------------------------------------------------------------- /算法笔试/顺丰/2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-29 19:53:13 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-29 20:26:40 7 | ''' 8 | size = int(input().strip()) 9 | nums = input().split() 10 | nums = [int(x) for x in nums] 11 | 12 | tail = [nums[0]] 13 | 14 | for i in range(1, size): 15 | left = 0 16 | right = len(tail) 17 | while left < right: 18 | mid = (left + right) >> 1 19 | 20 | if tail[mid] < nums[i]: 21 | left = mid + 1 22 | else: 23 | right = mid 24 | if left == len(tail): 25 | tail.append(nums[i]) 26 | else: 27 | tail[left] = nums[i] 28 | print(len(tail)) 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /算法笔试/顺丰/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-29 20:52:28 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-29 21:02:05 7 | ''' 8 | 9 | def union_find(nodes, edges): 10 | father = [0]*len(nodes) # 记录父节点 11 | for node in nodes: # 初始化为本身 12 | father[node] = node 13 | 14 | for edge in edges: # 标记父节点 15 | head = edge[0] 16 | tail = edge[1] 17 | father[tail] = head 18 | 19 | for node in nodes: 20 | while True: # 循环,直到找到根节点 21 | father_of_node = father[node] 22 | if father_of_node != father[father_of_node]: 23 | father[node] = father[father_of_node] 24 | else: # 如果该节点的父节点与其爷爷节点相同, 25 | break # 则说明找到了根节点 26 | 27 | L = {} 28 | for i, f in enumerate(father): 29 | L[f] = [] 30 | for i, f in enumerate(father): 31 | L[f].append(i) 32 | 33 | nodes = list(range(0, 10)) 34 | test_edges = [[0, 1], [0, 4], [1, 2], [1, 3], [5, 6], [6, 7], [7, 5], [8, 9]] 35 | 36 | L = union_find(nodes, test_edges) 37 | print(L) -------------------------------------------------------------------------------- /面试资料/APP汇总整理.md: -------------------------------------------------------------------------------- 1 | # APP汇总整理 2 | 3 | **社交**:微信、QQ、Facebook、Instgram、Twitter、Telegram、 4 | 5 | **购物**:淘宝、天猫、唯品会、京东、拼多多、 6 | 7 | **吃饭**:美团、口碑、下厨房、懒饭、便利峰、 8 | 9 | **影视娱乐**:抖音、多闪、猫眼、喜马拉雅、微博、小红书、bilibili、腾讯视频、王者荣耀、Play商店、游戏加速、讯飞输入法、SSRR、虎扑、天天P图、网易云音乐、 10 | 11 | **工作学习**:QQ邮箱、chrome浏览器、Medium、Quora、微信读书、TED、网易邮箱、BOSS直聘、牛客、 12 | 13 | **新闻**:彭盘新闻、界面新闻、知乎、墨迹、给未来的信 14 | 15 | **交通出行**:滴滴出行、亿通行、高德地图、12306、北京公交、链家、 16 | 17 | **财务管理**:智能财务、掌声生活、蚂蚁财富、工商银行、建设银行、工银融e联合、圈子账本、 -------------------------------------------------------------------------------- /面试资料/Bagging&Boosting.md: -------------------------------------------------------------------------------- 1 | # Bagging和Boosting的区别 2 | 3 | 1. **样本选择上** 4 | 5 | Bagging:训练集是在原始集中有放回选取的,从原始集中选出的各轮训练集之间是独立的。 6 | 7 | Boosting:每一轮的训练集不变,只是训练集中每个样例在分类器中的权重发生变化。而权值是根据上一轮的分类结果进行调整。 8 | 9 | 2. **样例权重** 10 | 11 | Bagging:使用均匀取样,每个样例的权重相等 12 | 13 | Boosting:根据错误率不断调整样例的权值,错误率越大则权重越大。 14 | 15 | 3. **预测函数** 16 | 17 | Bagging:所有预测函数的权重相等。 18 | 19 | Boosting:每个弱分类器都有相应的权重,对于分类误差小的分类器会有更大的权重。 20 | 21 | 4. **并行计算** 22 | 23 | Bagging:各个预测函数可以并行生成 24 | 25 | Boosting:各个预测函数只能顺序生成,因为后一个模型参数需要前一轮模型的结果。 26 | 27 | -------------------------------------------------------------------------------- /面试资料/Images/ELUs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/ELUs.png -------------------------------------------------------------------------------- /面试资料/Images/PReLU.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/PReLU.png -------------------------------------------------------------------------------- /面试资料/Images/ReLU_PReLU_RReLU.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/ReLU_PReLU_RReLU.jpeg -------------------------------------------------------------------------------- /面试资料/Images/relu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/relu.png -------------------------------------------------------------------------------- /面试资料/Images/sigmoid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/sigmoid.png -------------------------------------------------------------------------------- /面试资料/Images/tanh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/tanh.png -------------------------------------------------------------------------------- /面试资料/Images/常用神经网络结构图.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/常用神经网络结构图.jpeg -------------------------------------------------------------------------------- /面试资料/Images/损失函数.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/损失函数.png -------------------------------------------------------------------------------- /面试资料/Images/百度翻译_files/alog.min.js: -------------------------------------------------------------------------------- 1 | void function(a,b){function c(a){var c=D.get("alias")||{},d=c[a]||a+".js";if(!y[d]){y[d]=!0;var e="script",f=b.createElement(e),g=b.getElementsByTagName(e)[0];f.async=!0,f.src=d,g.parentNode.insertBefore(f,g)}}function d(a){if(!a.defined){for(var b=!0,d=[],f=a.requires,g=0;f&&ge;e++)d.push(a[e]);"function"==typeof c&&c.apply(this,d)}else this.argsList.push(a)}function m(a,b){var c={};for(var d in a)a.hasOwnProperty(d)&&(c[d]=a[d]);for(var d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);return c}function n(a){this.name=a,this.fields={protocolParameter:{postUrl:null,protocolParameter:null}},this.argsList=[],this.alog=z}function o(a){var b;if(a=a||"default","*"==a){b=[];for(var c in B)b.push(B[c]);return b}var d=B[a];return d||(d=B[a]=new n(a)),d}function p(){if(!(u&&new Date-s<50||t)){t=!0;var a=0;for(var b in B){var c=B[b];c.created&&(a+=c.fire("unload"))}if(a)for(var d=new Date;new Date-d<100;);}}var q=a.alogObjectName||"alog",r=a[q];if(!r||!r.defined){var s,t,u=b.all&&a.attachEvent,v=r&&r.l||+new Date,w=a.logId||(+new Date).toString(36)+Math.random().toString(36).substr(2,3),x=0,y={},z=function(a){var b,c,e,f,g=arguments;if("define"==a||"require"==a){for(var h=1;h=4)return null}return null}function g(a){b.attachEvent?b.attachEvent("onclick",a):b.addEventListener("click",a,!1)}var h=!1;e(),alog.fire&&alog.fire("mark"),g(function(b){var b=b||a.event,d=b.target||b.srcElement,e=f("a",d);if(e){var g=e.getAttribute("href");/^#|javascript:/.test(g)||c("PMS_JT",'({"s":'+ +new Date+',"r":"'+document.URL.replace(/#.*/,"")+'"})')}})}if(a){var c="http://fex.bdstatic.com",d="http://static.tieba.baidu.com",e=d;("https:"===window.location.protocol||a.https)&&(c="https://fex.bdstatic.com",d="https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK",e=d),alog("set","alias",{monkey:c+"/hunter/alog/monkey.min.js",element:c+"/hunter/alog/element.min.js?v=160118",speed:c+"/hunter/alog/speed.min.js?v=170721",feature:c+"/hunter/alog/feature.min.js?v=150727",csp:c+"/hunter/alog/dp.csp.min.js?v=140804",xss:c+"/hunter/alog/dp.xss.min.js?v=140804"});var f=a.product,g=a.page,h=a.monkey_page,i=a.speed_page,j=Math.random,k=d+"/tb/pms/img/st.gif",l=k,m=a.speed,n=a.monkey,o=a.exception,p=a.feature,q=a.csp,r=a.xss,s=a.cus;m&&(m.product_id=f,m.page_id=i?i:g,m.log_path||(m.log_path=k),alog("speed.set","options",m),b(window,document)),n&&n.sample&&j()0&&/^z_/.test(e)&&(d=!0,c[e]=b)):c.page=a[e];d&&alog("cus.send","time",c)}}),alog("cus.on","avg",function(a){var b,c={},d=!1;if("[object Object]"===a.toString()){for(var e in a)"page"!=e?(b=parseInt(a[e]),b>0&&/^z_/.test(e)&&(d=!0,c[e]=b)):c.page=a[e];d&&alog("cus.send","avg",c)}}),alog("cus.on","count",function(a){var b={},c=!1;if("string"==typeof a&&(a=[a]),a instanceof Array)for(var d=0;d"),d=document.body,f=b.length-1;0<=f;f--)if(-1"+d.join(">"):l,f.push(l)),d.unshift(encodeURIComponent(String(a.nodeName).toLowerCase())+(1"));return f};mt.f.tb=function(a){return(a= 7 | mt.f.oa(a,s))&&a.length?String(a[0]):""};mt.f.rb=function(a){return mt.f.oa(a,w)};mt.f.dc=function(a,b){for(b=b.toUpperCase();(a=a.parentNode)&&1==a.nodeType;)if(a.tagName==b)return a;return v};mt.f.lb=function(a){return 9===a.nodeType?a:a.ownerDocument||a.document};mt.f.ec=function(a){var b={top:0,left:0};if(!a)return b;var d=mt.f.lb(a).documentElement;"undefined"!==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect());return{top:b.top+(window.pageYOffset||d.scrollTop)-(d.clientTop||0),left:b.left+ 8 | (window.pageXOffset||d.scrollLeft)-(d.clientLeft||0)}};mt.f.getAttribute=function(a,b){var d=a.getAttribute&&a.getAttribute(b)||v;if(!d&&a.attributes&&a.attributes.length)for(var f=a.attributes,g=f.length,m=0;ma?"0"+a:a}var e={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};return function(d){switch(typeof d){case "undefined":return"undefined";case "number":return isFinite(d)?String(d):"null";case "string":return b(d);case "boolean":return String(d); 16 | default:if(d===v)return"null";if(d instanceof Array){var f=["["],g=d.length,e,l,p;for(l=0;l(new Date).getTime())return b.substring(a+1)}}else if(mt.localStorage.ea())try{return mt.localStorage.l.load(document.location.hostname),mt.localStorage.l.getAttribute(b)}catch(d){}return v}; 20 | mt.localStorage.remove=function(b){if(window.localStorage)window.localStorage.removeItem(b);else if(mt.localStorage.ea())try{mt.localStorage.l.load(document.location.hostname),mt.localStorage.l.removeAttribute(b),mt.localStorage.l.save(document.location.hostname)}catch(a){}};mt.sessionStorage={};mt.sessionStorage.set=function(b,a){try{window.sessionStorage&&window.sessionStorage.setItem(b,a)}catch(e){}}; 21 | mt.sessionStorage.get=function(b){try{return window.sessionStorage?window.sessionStorage.getItem(b):v}catch(a){return v}};mt.sessionStorage.remove=function(b){try{window.sessionStorage&&window.sessionStorage.removeItem(b)}catch(a){}};mt.Sa={};mt.Sa.log=function(b,a){var e=new Image,d="mini_tangram_log_"+Math.floor(2147483648*Math.random()).toString(36);window[d]=e;e.onload=function(){e.onload=v;e=window[d]=v;a&&a(b)};e.src=b};mt.xa={}; 22 | mt.xa.wb=function(){var b="";if(navigator.plugins&&navigator.mimeTypes.length){var a=navigator.plugins["Shockwave Flash"];a&&a.description&&(b=a.description.replace(/^.*\s+(\S+)\s+\S+$/,"$1"))}else if(window.ActiveXObject)try{if(a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))(b=a.GetVariable("$version"))&&(b=b.replace(/^.*\s+(\d+),(\d+).*$/,"$1.$2"))}catch(e){}return b}; 23 | mt.xa.bc=function(b,a,e,d,f){return''};mt.url={}; 24 | mt.url.m=function(b,a){var e=b.match(RegExp("(^|&|\\?|#)("+a+")=([^&#]*)(&|$|#)",""));return e?e[3]:v};mt.url.fc=function(b){return(b=b.match(/^(https?:)\/\//))?b[1]:v};mt.url.ob=function(b){return(b=b.match(/^(https?:\/\/)?([^\/\?#]*)/))?b[2].replace(/.*@/,""):v};mt.url.N=function(b){return(b=mt.url.ob(b))?b.replace(/:\d+$/,""):b};mt.url.oa=function(b){return(b=b.match(/^(https?:\/\/)?[^\/]*(.*)/))?b[2].replace(/[\?#].*/,"").replace(/^$/,"/"):v}; 25 | (function(){function b(){for(var a=w,b=document.getElementsByTagName("script"),d=b.length,d=100l*g.split(">").length)for(g=0;g").length,l=0;l"));a&&(b.d(a,"Object")&&a.Ea)&&a.Ea(e)},Kb:function(a, 36 | b){return function(e){(e.target||e.srcElement).setAttribute(a.da,e.clientX+":"+e.clientY);a&&a.r&&(b?a.r(b):a.r("#"+encodeURIComponent(this.id),e.type))}}};return h.ma=e})(); 37 | (function(){var b=mt.f,a=mt.o,e=mt.event,d=mt.lang,f=h.ma,g=h.V,m=g.T,l={da:"HM_ce",Va:function(){if(c.cetrk&&c.cetrk.length){e.e(document,"click",f.U(l,c.cetrk));for(var d=0,g=c.cetrk.length;d")&&(0===u.indexOf("#")&&(u=u.substring(1)),(u=b.Ga(u))&&e.e(u,"click",f.Kb(l,m)))}}},Ea:function(b){if(c.cetrk&&c.cetrk.length)for(var d=0,f=c.cetrk.length;df.ia||(encodeURIComponent(x.join("!")+a).length>f.ia&&(t.r(x.join("!")),x=[]), 42 | x.push(a))},r:function(a){h.c.b.et=5;h.c.b.ep=a;h.c.b.p=l(m.C("autoEventTracking"));h.c.i();h.c.b.p=""},S:function(){return function(){x&&x.length&&(t.r(x.join("!")),x=[])}}};b.aa(c.aet)&&""!==c.aet&&g.e("pv-b",function(){e.e(document,"click",t.U());"ontouchend"in document&&e.e(window,"touchend",t.U());e.e(window,"unload",t.S())});return t})(); 43 | (function(){var b=mt.event,a=mt.h,e=h.A,d=h.I,f=+new Date,g=[],m=v,l={gb:function(){return function(){h.c&&(h.c.P&&c.aet&&c.aet.length)&&(window.clearTimeout(m),m=window.setTimeout(function(){l.Xa(a.Y()+a.O())},150))}},Xa:function(a){l.ga([+new Date-(h.c.D!==r?h.c.D:f),a].join("*"))},ga:function(a){if(encodeURIComponent(g.join("!")+a).length>e.ia||3a.length)){var b=a[1],e=a[4]||3;if(0b&&0e){k.ca++;for(var f=(h.c.b.cv||"*").split("!"),g=f.length;ga.length)){var e=d.g(a[1]);a=d.g(a[2]);if(e!==r&&a!==r){var y=decodeURIComponent(t.getData("Hm_ct_"+c.id)||""),y=b(y,e,1,a);t.setData("Hm_ct_"+c.id,encodeURIComponent(y),c.age)}}},_setVisitTag:function(a){if(!(3>a.length)){var e=d.g(a[1]);a=d.g(a[2]);if(e!== 55 | r&&a!==r){var y=k.z.za,y=b(y,e,2,a);k.z.za=y}}},_setPageTag:function(a){if(!(3>a.length)){var e=d.g(a[1]);a=d.g(a[2]);if(e!==r&&a!==r){var y=k.z.page,y=b(y,e,3,a);k.z.page=y}}},_setReferrerOverride:function(a){1c.vdur?1:4;var b=w;this.Z(document.referrer)&&this.Z(document.location.href)?b=s:(b=a.N(document.referrer),b=this.Q(b||"",document.location.hostname));return b?k.G-k.K>c.vdur?1:4:3},Qb:function(){var a,b,d,e,f;k.K=t.getData("Hm_lpvt_"+c.id)||0;13===k.K.length&&(k.K=Math.round(k.K/1E3));b=this.ub();a=4!==b?1:0;if(d=t.getData("Hm_lvt_"+c.id)){e=d.split(",");for(f=e.length-1;0<=f;f--)13===e[f].length&&(e[f]=""+Math.round(e[f]/1E3)); 64 | for(;2592E3e.length?2:3;for(1===a&&e.push(k.G);4=+new Date-g;);};if(c.med)g="/zoosnet",f="swt",m=/swt|zixun|call|chat|zoos|business|talk|kefu|openkf|online|\/LR\/Chatpre\.aspx/i,l={click:function(){for(var a=[],b=p(document.getElementsByTagName("a")),b=[].concat.apply(b,p(document.getElementsByTagName("area"))),b=[].concat.apply(b,p(document.getElementsByTagName("img"))),d,e,f=0,g=b.length;f百度翻译 -------------------------------------------------------------------------------- /面试资料/Images/百度翻译_files/mod_b80b8f9.js: -------------------------------------------------------------------------------- 1 | var require,define;!function(e){if(!require){var r=document.getElementsByTagName("head")[0],t={},n={},i={},a={},u={},o={},s=function(e,t){for(var n=document.createDocumentFragment(),i=0,u=e.length;u>i;i++){var o=e[i].id,s=e[i].url; 2 | if(!(s in a)){a[s]=!0;var c=document.createElement("script");t&&!function(e,r){var n=setTimeout(function(){t(r)},require.timeout); 3 | e.onerror=function(){clearTimeout(n),t(r)};var i=function(){clearTimeout(n)};"onload"in e?e.onload=i:e.onreadystatechange=function(){("loaded"===this.readyState||"complete"===this.readyState)&&i() 4 | }}(c,o),c.type="text/javascript",c.src=s,n.appendChild(c)}}r.appendChild(n)},c=function(e,r,n){for(var i=[],a=0,c=e.length;c>a;a++){var l=e[a],p=t[l]||(t[l]=[]); 5 | p.push(r);var f,d=u[l]||u[l+".js"]||{},h=d.pkg;f=h?o[h].url||o[h].uri:d.url||d.uri||l,i.push({id:l,url:f})}s(i,n)};define=function(e,r){e=e.replace(/\.js$/i,""),n[e]=r; 6 | var i=t[e];if(i){for(var a=0,u=i.length;u>a;a++)i[a]();delete t[e]}},require=function(e){if(e&&e.splice)return require.async.apply(this,arguments); 7 | e=require.alias(e);var r=i[e];if(r)return r.exports;var t=n[e];if(!t)throw"[ModJS] Cannot find module `"+e+"`";r=i[e]={exports:{}}; 8 | var a="function"==typeof t?t.apply(r,[require,r.exports,r]):t;return a&&(r.exports=a),r.exports},require.async=function(r,t,i){function a(e){for(var r,t=0,i=e.length;i>t;t++){var o=require.alias(e[t]); 9 | o in s||(s[o]=!0,o in n?(r=u[o]||u[o+".js"],r&&"deps"in r&&a(r.deps)):(p.push(o),l++,r=u[o]||u[o+".js"],r&&"deps"in r&&a(r.deps))) 10 | }}function o(){if(0===l--){for(var n=[],i=0,a=r.length;a>i;i++)n[i]=require(r[i]);t&&t.apply(e,n)}}"string"==typeof r&&(r=[r]); 11 | var s={},l=0,p=[];a(r),c(p,o,i),o()},require.ensure=function(e,r){require.async(e,function(){r&&r.call(this,require)})},require.resourceMap=function(e){var r,t; 12 | t=e.res;for(r in t)t.hasOwnProperty(r)&&(u[r]=t[r]);t=e.pkg;for(r in t)t.hasOwnProperty(r)&&(o[r]=t[r])},require.loadJs=function(e){if(!(e in a)){a[e]=!0; 13 | var t=document.createElement("script");t.type="text/javascript",t.src=e,r.appendChild(t)}},require.loadCss=function(e){if(e.content){var t=document.createElement("style"); 14 | t.type="text/css",t.styleSheet?t.styleSheet.cssText=e.content:t.innerHTML=e.content,r.appendChild(t)}else if(e.url){var n=document.createElement("link"); 15 | n.href=e.url,n.rel="stylesheet",n.type="text/css",r.appendChild(n)}},require.alias=function(e){return e.replace(/\.js$/i,"") 16 | },require.timeout=5e3}}(this); -------------------------------------------------------------------------------- /面试资料/Images/百度翻译_files/public_842c19c.css: -------------------------------------------------------------------------------- 1 | 2 | body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0} 3 | table{border-collapse:collapse;border-spacing:0} 4 | fieldset,img{border:0;vertical-align:top} 5 | address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:400} 6 | ol,ul{list-style:none} 7 | caption,th{text-align:left} 8 | h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:400} 9 | q:before,q:after{content:""} 10 | abbr,acronym{border:0;font-variant:normal} 11 | sup{vertical-align:text-top} 12 | sub{vertical-align:text-bottom} 13 | input,textarea,select{font-family:inherit;font-size:inherit} 14 | legend{color:#000} 15 | .inner-te,.inner{margin:0 auto} 16 | @media (max-width:1278px){.inner-te,.inner{width:993px}} 17 | @media (min-width:1279px) and (max-width:1506px){.inner-te,.inner{margin:0 143px;width:auto}} 18 | @media (min-width:1507px){.inner-te,.inner{width:1220px}} 19 | body{font:12px Arial,"PingFang SC","Hiragino Sans GB",STHeiti,"Microsoft YaHei","WenQuanYi Micro Hei",sans-serif} 20 | html,body{background:#fff} 21 | body.no-interaction{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} 22 | a{text-decoration:none;color:#666} 23 | a:hover{text-decoration:underline} 24 | i{font-style:normal} 25 | .clearfix:before,.clearfix:after{content:" ";display:table} 26 | .clearfix:after{clear:both} 27 | .container{background:#fff} 28 | .cut-font{overflow:hidden;white-space:nowrap;-o-text-overflow:ellipsis;text-overflow:ellipsis} 29 | .card-shadow{-webkit-box-shadow:1px 2px 1px 0 rgba(0,0,0,.072);-moz-box-shadow:1px 2px 1px 0 rgba(0,0,0,.072);box-shadow:1px 2px 1px 0 rgba(0,0,0,.072);filter:progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color="#e3e3e3") \9} 30 | .arrow{display:inline-block;width:0;height:0;font-size:0} 31 | .hide{display:none} 32 | .show{display:block} 33 | #passport-login-pop{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box} 34 | .download-guide{height:36px;float:right;position:relative;padding-left:26px} 35 | .download-guide:before{content:'';position:absolute;left:0;bottom:0;top:0;margin:auto 0;width:1px;height:13px;background-color:#999} 36 | .download-guide-ul{width:100%;height:100%;list-style:none} 37 | .download-guide-ul .guide-list{display:inline-block;float:left;height:36px;width:98px;color:#666;cursor:pointer;border:1px solid transparent;position:relative} 38 | .download-guide-ul .guide-list:hover{background-color:#fcfcfc;border:1px solid #eee} 39 | .download-app:hover .app-contain{display:block;text-decoration:none} 40 | .app-list-name:hover{text-decoration:none} 41 | .guide-list .list-name{width:100%;height:100%;display:block;text-align:center;line-height:36px} 42 | .app-contain{position:relative;width:100px;height:140px;display:none;z-index:999;left:-1px;background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/download-app_2138970.png);background-repeat:no-repeat;-webkit-background-size:100% 100%;-moz-background-size:100%;background-size:100%;border:1px solid #eee;text-decoration:none;padding-top:100px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} 43 | .download-guide-ul .guide-list.download-plugin{width:64px} 44 | .download-plugin:hover .plugin-contain{display:block} 45 | .plugin-contain{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:463px;position:absolute;z-index:99;background-color:#fff;left:-170px;top:36px;border:1px solid #eee;font-family:Arial,"PingFang SC","Hiragino Sans GB",STHeiti,"Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;padding-top:30px;padding-left:25px;padding-bottom:30px;display:none;cursor:default} 46 | .plugin-contain *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} 47 | .plugin-contain a:hover{text-decoration:none} 48 | .plugin-contain h2{font-size:16px;color:#000;line-height:16px} 49 | .plugin-contain .note{font-size:12px;color:#CCC;vertical-align:middle} 50 | .plugin-contain .desc{font-size:12px;color:#999;line-height:28px} 51 | .plugin-contain .browser-border,.plugin-contain .logo-list-li{border:1px solid #e5e5e5} 52 | .plugin-contain .browser-border:hover,.plugin-contain .logo-list-li:hover{border-color:#00a0e9} 53 | .plugin-contain .ocr-extension-browser{display:block;width:138px;height:58px;padding-left:62px;line-height:56px;font-size:12px;color:#4A4A4A;margin:7px 0 30px;background-repeat:no-repeat;background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/chrome_6767d2f.png);-webkit-background-size:32px 32px;-moz-background-size:32px 32px;background-size:32px 32px;background-position:20px center} 54 | .plugin-contain .logo-list{font-size:0} 55 | .plugin-contain .logo-list-li{margin-top:7px;margin-right:7px;width:63px;height:63px;position:relative;display:inline-block;vertical-align:top} 56 | .plugin-contain .logo-list-li a{position:absolute;width:100%;height:100%;top:0;left:0;text-align:center;padding-top:40px;-webkit-background-size:30px 30px;-moz-background-size:30px 30px;background-size:30px 30px;background-repeat:no-repeat;background-position:center 7px} 57 | .plugin-contain .logo-list-li span{font-size:12px;line-height:1;-webkit-transform:scale(0.8);-moz-transform:scale(0.8);-ms-transform:scale(0.8);-o-transform:scale(0.8);transform:scale(0.8);display:inline-block} 58 | .plugin-contain .browser1 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/chrome_6767d2f.png)} 59 | .plugin-contain .browser2 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/baidu_b76f076.png)} 60 | .plugin-contain .browser3 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/qq_6c105d0.png)} 61 | .plugin-contain .browser4 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/360_f91f361.png)} 62 | .plugin-contain .browser5 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/360speed_c333d6c.png)} 63 | .plugin-contain .browser6 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/cheetah_a9595c4.png)} 64 | .plugin-contain .browser7 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/uc_948a046.png)} 65 | .plugin-contain .browser8 a{background-image:url(//fanyi.bdstatic.com/static/translation/widget/header/downloadGuide/img/opera_ce2f8fc.png)} 66 | .app-contain{text-align:center} 67 | 68 | .header{height:31px;line-height:31px;padding:14px 0;background:#fff} 69 | .logo-image{padding-top:0} 70 | .menu-text{height:49px;margin:0 0 0 50px} 71 | .logo-activity{width:152px;height:48px;margin-top:-14px;margin-left:16px} 72 | .divide-wrap{position:relative;height:1px;z-index:1} 73 | .colorbar{width:100%;height:100%;z-index:11;background:url(//fanyi.bdstatic.com/static/translation/img/header/colorbar_623c2a2.png) center no-repeat;position:relative} 74 | .colorbar-before{content:"";position:absolute;left:0;width:50%;height:100%;z-index:9;background-color:#1b24ff} 75 | .colorbar-after{content:"";position:absolute;right:0;width:50%;height:100%;z-index:9;background-color:#fd0371} 76 | .logo{float:left;height:auto!important;zoom:1} 77 | .logo-image{display:inline-block;vertical-align:top;font:14px Arial,"PingFang SC","Hiragino Sans GB",STHeiti,"Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;color:#9b9b9b} 78 | .manual-trans-info{margin-right:17px;position:relative;height:38px;color:#333;float:right;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} 79 | .manual-trans-info *{-webkit-box-sizing:inherit;-moz-box-sizing:inherit;box-sizing:inherit} 80 | .manual-trans-info .list-name{position:relative;display:block;width:82px;text-align:center;line-height:38px;border:1px solid transparent} 81 | .manual-trans-info:hover a{text-decoration:none} 82 | .manual-trans-info:hover .list-name{border:1px solid #eee;background-color:#fcfcfc} 83 | .manual-trans-info .list-container{display:none;position:absolute;left:-139px;top:37px;width:360px;border:1px solid #eee;font-size:14px;text-align:center;background-color:#fff;z-index:99} 84 | .manual-trans-info .list-container{padding:25px 25px 30px} 85 | .entry-trans-info:hover .list-container{display:block} 86 | .manual-trans-info .list-container .content-text{height:24px;margin:0;line-height:24px} 87 | .manual-trans-info .list-container .content-text .content-text-num{color:#4395ff} 88 | .manual-trans-info .infolist-ul{width:100%;height:100%;list-style:none;margin-top:17px} 89 | .manual-trans-info .info-li{float:left;width:144px;height:155px;margin:0 5px;border:1px solid #f1f1f1} 90 | .manual-trans-info .info-li:hover{border:1px solid #00a4ed} 91 | .manual-trans-info .info-li h1{line-height:14px;margin:16px 0 13px} 92 | .manual-trans-info .info-li p{font-size:12px;line-height:24px;color:#999} 93 | .navigation{float:right;zoom:1} 94 | .navigation li{display:inline-block;*display:inline;*zoom:1;vertical-align:top} 95 | .navigation li .split-line{margin:0 10px} 96 | .account-wrap{position:relative;height:36px;z-index:2} 97 | .account-wrap .arrow-down{margin-left:5px;vertical-align:-2px;_vertical-align:-4px} 98 | .account-head{line-height:36px;height:36px;display:inline-block;min-width:56px;padding:1px 11px} 99 | .account-panel{position:absolute;border:1px solid #eee;border-bottom:0;background:#fff;right:0;top:0;min-width:76px;display:none} 100 | .account-panel li{display:block} 101 | .account-panel li a{display:block;padding:0 10px;height:36px;line-height:36px;border-bottom:1px solid #eee;text-decoration:none;text-align:left} 102 | .account-panel li a:hover{background:#fcfcfc} 103 | .wrap-login .account-head{width:53px;padding-left:24px;padding-right:0} 104 | .wrap-login .account-panel{min-width:78px} 105 | .account-panel .account-login,.account-panel .account-register{padding-left:23px} 106 | .header .inner{*position:relative} 107 | .browser-edition-tip{position:absolute;left:200px;height:25px;line-height:25px;background:#fffdf0;padding:0 10px} 108 | .simultaneous-interpretation{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;float:right;position:relative;height:38px;color:#666;border:1px solid transparent} 109 | .simultaneous-interpretation:hover{border:1px solid #eee;background-color:#fcfcfc} 110 | .simultaneous-interpretation *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} 111 | .simultaneous-interpretation a{display:inline-block;padding:1px 17px 0;line-height:36px} 112 | .simultaneous-interpretation a:hover{text-decoration:none} 113 | .simultaneous-interpretation .icon-hotlk{position:absolute;top:-1px;right:-4px} 114 | .trans-machine{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;float:right;position:relative;height:38px;color:#666;border:1px solid transparent} 115 | .trans-machine:hover{border:1px solid #eee;background-color:#fcfcfc} 116 | .trans-machine *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} 117 | .trans-machine a{display:inline-block;padding:1px 17px 0;line-height:36px} 118 | .trans-machine a:hover{text-decoration:none} 119 | .trans-machine .icon-hotlk{position:absolute;top:-1px;right:-4px} 120 | /*!-------------------------------------------------------------------- 121 | STYLES "Outdated Browser" 122 | Version: 1.1.2 - 2015 123 | author: Burocratik 124 | website: http://www.burocratik.com 125 | * @preserve 126 | -----------------------------------------------------------------------*/ 127 | #outdated{display:none;position:fixed;top:0;left:0;width:100%;height:170px;text-align:center;text-transform:uppercase;z-index:1500;background-color:#f25648;color:#fff} 128 | * html #outdated{position:absolute} 129 | #outdated h6{font-size:25px;line-height:25px;margin:30px 0 10px} 130 | #outdated p{font-size:16px;line-height:12px;margin-top:40px} 131 | #outdated a{font-weight:700;color:#fff} 132 | #outdated #btnUpdateBrowser{display:block;position:relative;padding:10px 20px;margin:30px auto 0;width:230px;color:#fff;text-decoration:none;border:2px solid #fff;cursor:pointer} 133 | #outdated #btnUpdateBrowser:hover{color:#f25648;background-color:#fff} 134 | #outdated .last{position:absolute;top:10px;right:25px;width:20px;height:20px} 135 | #outdated .last[dir=rtl]{right:auto!important;left:25px!important} 136 | #outdated #btnCloseUpdateBrowser{display:block;position:relative;width:100%;height:100%;text-decoration:none;color:#fff;font-size:36px;line-height:36px} 137 | .scroll-wrapper{overflow:hidden!important;padding:0!important;position:relative} 138 | .scroll-wrapper>.scroll-content{border:0!important;-webkit-box-sizing:content-box!important;-moz-box-sizing:content-box!important;box-sizing:content-box!important;height:auto;left:0;margin:0;max-height:none;max-width:none!important;overflow:scroll!important;padding:0;position:relative!important;top:0;width:auto!important} 139 | .scroll-wrapper>.scroll-content::-webkit-scrollbar{height:0;width:0} 140 | .scroll-element{display:none} 141 | .scroll-element,.scroll-element div{-webkit-box-sizing:content-box!important;-moz-box-sizing:content-box!important;box-sizing:content-box!important} 142 | .scroll-element.scroll-x.scroll-scrollx_visible,.scroll-element.scroll-y.scroll-scrolly_visible{display:block} 143 | .scroll-element .scroll-bar,.scroll-element .scroll-arrow{cursor:default} 144 | .scroll-textarea{border:1px solid #ccc;border-top-color:#999} 145 | .scroll-textarea>.scroll-content{overflow:hidden!important} 146 | .scroll-textarea>.scroll-content>textarea{border:0!important;-webkit-box-sizing:border-box!important;-moz-box-sizing:border-box!important;box-sizing:border-box!important;height:100%!important;margin:0;max-height:none!important;max-width:none!important;overflow:scroll!important;outline:0;padding:2px;position:relative!important;top:0;width:100%!important} 147 | .scroll-textarea>.scroll-content>textarea::-webkit-scrollbar{height:0;width:0} 148 | .scrollbar-inner>.scroll-element,.scrollbar-inner>.scroll-element div{border:0;margin:0;padding:0;position:absolute;z-index:10} 149 | .scrollbar-inner>.scroll-element div{display:block;height:100%;left:0;top:0;width:100%} 150 | .scrollbar-inner>.scroll-element.scroll-x{bottom:2px;height:8px;left:0;width:100%} 151 | .scrollbar-inner>.scroll-element.scroll-y{height:100%;right:2px;top:0;width:4px} 152 | .scrollbar-inner>.scroll-element .scroll-element_outer{overflow:hidden} 153 | .scrollbar-inner>.scroll-element .scroll-element_outer,.scrollbar-inner>.scroll-element .scroll-element_track,.scrollbar-inner>.scroll-element .scroll-bar{-webkit-border-radius:8px;-moz-border-radius:8px;border-radius:8px} 154 | .scrollbar-inner>.scroll-element .scroll-bar{background-color:#e1e1e1} 155 | .scrollbar-inner>.scroll-element.scroll-draggable .scroll-bar{background-color:#919191} 156 | .scrollbar-inner>.scroll-element.scroll-x.scroll-scrolly_visible .scroll-element_track{left:-12px} 157 | .scrollbar-inner>.scroll-element.scroll-y.scroll-scrollx_visible .scroll-element_track{top:-12px} 158 | .scrollbar-inner>.scroll-element.scroll-x.scroll-scrolly_visible .scroll-element_size{left:-12px} 159 | .scrollbar-inner>.scroll-element.scroll-y.scroll-scrollx_visible .scroll-element_size{top:-12px} 160 | .webuploader-container{position:relative} 161 | .webuploader-element-invisible{position:absolute!important;clip:rect(1px 1px 1px 1px);clip:rect(1px,1px,1px,1px)} 162 | .webuploader-pick{position:relative} 163 | .webuploader-pick-hover{} 164 | .webuploader-pick-disable{opacity:.6;pointer-events:none} 165 | 166 | .inner-te{margin:0 auto} 167 | @media (max-width:1278px){.inner-te{width:993px}} 168 | @media (min-width:1279px) and (max-width:1506px){.inner-te{margin:0 143px;width:auto}} 169 | @media (min-width:1507px){.inner-te{width:1220px}} -------------------------------------------------------------------------------- /面试资料/Images/百度翻译_files/saved_resource.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /面试资料/Images/百度翻译_files/uni_login_wrapper.js: -------------------------------------------------------------------------------- 1 | function isSingleInstanceProd(s){var i=["mn","ma","im_hi"];return("|"+i.join("|")+"|").indexOf("|"+s+"|")>-1}function isLoginInstance(s){return s=s||"login",s+""=="login"}function saveInitInstance(s){window._pass_popinit_instance=s}function getInitInstance(){return window._pass_popinit_instance}var passport=passport||window.passport||{};passport._modulePool=passport._modulePool||{},passport._define=passport._define||function(s,i){passport._modulePool[s]=i&&i()},passport._getModule=passport._getModule||function(s){return passport._modulePool[s]};var passport=window.passport||{};passport.pop=passport.pop||{},passport.pop.insertScript=passport.pop.insertScript||function(s,i){var n=document,a=n.createElement("SCRIPT");a.type="text/javascript",a.charset="UTF-8",a.readyState?a.onreadystatechange=function(){("loaded"===a.readyState||"complete"===a.readyState)&&(a.onreadystatechange=null,i&&i())}:a.onload=function(){i&&i()},a.src=s,n.getElementsByTagName("head")[0].appendChild(a)},passport.ieVersion=function(){var s,i=navigator.userAgent.toLowerCase(),n=i.indexOf("msie")>-1;return n&&(s=i.match(/msie ([\d.]+)/)[1]),s},passport.pop.init=passport.pop.init||function(s){var i={"http:":"http://passport.bdimg.com","https:":"https://passport.bdimg.com"};if(passport.ieVersion()<=8&&(i={"http:":"http://passport.baidu.com","https:":"https://passport.baidu.com"}),isSingleInstanceProd(s.apiOpt.product)&&isLoginInstance(s.type)&&getInitInstance())return getInitInstance();var n;n=s&&"https"===s.protocol?"https:":window.location?window.location.protocol.toLowerCase():document.location.protocol.toLowerCase();var a=["pp","mn","wk","cmovie","translate","baidugushitong","ik","exp","waimai","jn","im","do","yuedu","hao123","tb","netdisk","developer","newdev","image_eco","zbsc","bpit_hcm","defensor","study","bizcrm"],e=s&&s.apiOpt&&s.apiOpt.product||"",t=("|"+a.join("|")+"|").indexOf("|"+e+"|")>-1,p=t?"/passApi/js/uni_loginv4_4400f49.js":"/passApi/js/uni_login_04b32ba.js",c=t?"/passApi/js/uni_loginv4_tangram_baa8786.js":"/passApi/js/uni_login_tangram_5ab408a.js",o=t?"/passApi/css/uni_loginv4_35dda7d.css":"/passApi/css/uni_login_new_5b1f23c.css",_={uni_login:p,uni_login_tangram:c,uni_loginPad:"/passApi/js/uni_loginPad_5c5f3bf.js",uni_loginPad_tangram:"/passApi/js/uni_loginPad_tangram_cf49c93.js",uni_smsloginEn:"/passApi/js/uni_smsloginEn_adaeb9a.js",uni_smsloginEn_tangram:"/passApi/js/uni_smsloginEn_tangram_d2a9ec7.js",uni_loginWap:"/passApi/js/uni_loginWap_3ffd0a9.js",uni_loginWap_tangram:"/passApi/js/uni_loginWap_3ffd0a9.js",uni_accConnect:"/passApi/js/uni_accConnect_8c8f536.js",uni_accConnect_tangram:"/passApi/js/uni_accConnect_tangram_4d6ccde.js",uni_accRealName:"/passApi/js/uni_accRealName_d02f29d.js",uni_accRealName_tangram:"/passApi/js/uni_accRealName_tangram_17a76fa.js",uni_checkPhone:"/passApi/js/uni_checkPhone_60c5752.js",uni_checkPhone_tangram:"/passApi/js/uni_checkPhone_tangram_7245786.js",uni_checkIDcard:"/passApi/js/uni_checkIDcard_71e8a00.js",uni_checkIDcard_tangram:"/passApi/js/uni_checkIDcard_tangram_0c6e8fa.js",uni_accSetPwd:"/passApi/js/uni_accSetPwd_ed1e1da.js",uni_accSetPwd_tangram:"/passApi/js/uni_accSetPwd_tangram_b10659a.js",uni_IDCertify:"/passApi/js/uni_IDCertify_44f589a.js",uni_IDCertify_tangram:"/passApi/js/uni_IDCertify_tangram_3c693ff.js",uni_travelComplete:"/passApi/js/uni_travelComplete_a349a9a.js",uni_travelComplete_tangram:"/passApi/js/uni_travelComplete_tangram_8104b14.js",uni_bindGuide:"/passApi/js/uni_bindGuide_d24cab2.js",uni_bindGuide_tangram:"/passApi/js/uni_bindGuide_tangram_0358a0f.js",uni_fillUserName:"/passApi/js/uni_fillUserName_6c35234.js",uni_fillUserName_tangram:"/passApi/js/uni_fillUserName_tangram_8494b93.js",uni_IDCertifyQrcode:"/passApi/js/uni_IDCertifyQrcode_cd2a7df.js",uni_IDCertifyQrcode_tangram:"/passApi/js/uni_IDCertifyQrcode_tangram_b55b54f.js",uni_loadingApi:"/passApi/js/uni_loadingApi_588b68f.js",uni_loadingApi_tangram:"/passApi/js/uni_loadingApi_tangram_10f40d7.js",uni_secondCardList:"/passApi/js/uni_secondCardList_242fe72.js",uni_secondCardList_tangram:"/passApi/js/uni_secondCardList_tangram_3abb1d6.js",uni_secondCardVerify:"/passApi/js/uni_secondCardVerify_4819486.js",uni_secondCardVerify_tangram:"/passApi/js/uni_secondCardVerify_tangram_05adce4.js",uni_multiBind:"/passApi/js/uni_multiBind_ac12159.js",uni_multiBind_tangram:"/passApi/js/uni_multiBind_tangram_f29d848.js",uni_multiUnbind:"/passApi/js/uni_multiUnbind_f93018c.js",uni_multiUnbind_tangram:"/passApi/js/uni_multiUnbind_tangram_27f8df5.js",uni_changeUser:"/passApi/js/uni_changeUser_092e54f.js",uni_changeUser_tangram:"/passApi/js/uni_changeUser_tangram_bdb64d6.js",uni_loginMultichoice:"/passApi/js/uni_loginMultichoice_5564416.js",uni_loginMultichoice_tangram:"/passApi/js/uni_loginMultichoice_tangram_2855ef0.js",uni_confirmWidget:"/passApi/js/uni_confirmWidget_5342cfa.js",uni_confirmWidget_tangram:"/passApi/js/uni_confirmWidget_tangram_0581d0f.js"},r={login:o,loginWap:"/passApi/css/uni_loginWap_f57424a.css",smsloginEn:"/passApi/css/uni_smsloginEn_eef0a6a.css",accConnect:"/passApi/css/uni_accConnect_ab6dda9.css",accRealName:"/passApi/css/uni_accRealName_a224a37.css",secondCardVerify:"/passApi/css/uni_secondCardVerify_1a69328.css",secondCardList:"/passApi/css/uni_secondCardList_ce6244a.css",checkPhone:"/passApi/css/uni_checkPhone_cd7c7a0.css",checkIDcard:"/passApi/css/uni_checkIDcard_be79680.css",accSetPwd:"/passApi/css/uni_accSetPwd_29f7784.css",IDCertify:"/passApi/css/uni_IDCertify_36e091b.css",IDCertifyQrcode:"/passApi/css/uni_IDCertifyQrcode_1e8827b.css",loadingApi:"/passApi/css/uni_loadingApi_f8732c0.css",loginPad:"/passApi/css/uni_loginPad_af389a4.css",multiBind:"/passApi/css/uni_multiBind_e8d24e4.css",multiUnbind:"/passApi/css/uni_multiUnbind_21428a6.css",changeUser:"/passApi/css/uni_changeUser_c7ae7b4.css",loginMultichoice:"/passApi/css/uni_loginMultichoice_289d3a0.css",confirmWidget:"/passApi/css/uni_confirmWidget_3d41f3b.css",uni_rebindGuide:"/passApi/css/uni_rebindGuide_347ecf2.css",travelComplete:"/passApi/css/uni_travelComplete_b06b013.css",bindGuide:"/passApi/css/uni_bindGuide_35d4a06.css",fillUserName:"/passApi/css/uni_fillUserName_931cb17.css"},u=i[n]||i["https:"];s=s||{},s.type=s.type||"login";var d,l=document,m=("_PassUni"+(new Date).getTime(),u+r[s.type]);s.cssUrlWrapper&&(m=cssUrlWrapper.join(t?"uni_loginv4.css":"uni_login.css")),d={show:function(){return d.loadPass(s.apiOpt),d.willShow=!0,d},setSubpro:function(i){return s.apiOpt&&(s.apiOpt.subpro=i),d},setMakeText:function(i){return s.apiOpt&&(s.apiOpt.makeText=i),d},loadPass:function(){var i=l.createElement("link");i.rel="stylesheet",i.type="text/css",i.href=m,i.disabled=!1,i.setAttribute("data-for","result"),l.getElementsByTagName("head")[0].appendChild(i),d.show=function(){return d.willShow=!0,d},s.plugCss&&(i=l.createElement("link"),i.rel="stylesheet",i.type="text/css",i.href=s.plugCss,i.disabled=!1,i.setAttribute("data-for","result"),l.getElementsByTagName("head")[0].appendChild(i)),d.passCallback(),delete d.loadPass},passCallback:function(){passport.pop.insertScript("https://wappass.baidu.com/static/waplib/moonshad.js?tt="+(new Date).getTime(),function(){d.components.length>0?passport.pop.insertScript(d.components.shift(),d.passCallback):(passport.pop[s.type](s,d,function(){d.willShow&&d.show(),s&&s.onRender&&s.onRender()}),delete d.passCallback,delete d.components)})},components:[]};var g="uni_"+s.type;return s.tangram&&(g+="_tangram"),s.apiOpt&&s.apiOpt.product+""=="ik"&&Math.random()<.3&&(d.components.push(u+"/passApi/js/uni/passhunt.js"),s.hunter=!0),d.components.push(u+_[g]),s.cache&&d.loadPass(s.apiOpt),s.id&&l.getElementById(s.id)&&(l.getElementById(s.id).onclick=function(){d.show()}),isSingleInstanceProd(s.apiOpt.product)&&isLoginInstance(s.type)&&saveInitInstance(d),d}; -------------------------------------------------------------------------------- /面试资料/Images/百度翻译_files/wechat_76663d3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/百度翻译_files/wechat_76663d3.jpg -------------------------------------------------------------------------------- /面试资料/Images/百度翻译_files/weibo_669233c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/Images/百度翻译_files/weibo_669233c.png -------------------------------------------------------------------------------- /面试资料/Python核心知识点.md: -------------------------------------------------------------------------------- 1 | ## 迭代学习Python核心知识点 2 | 3 | 装饰器 4 | 5 | 迭代器 6 | 7 | Python数据结构一些底层的实现原理,为何这么快。如字典,集合等 8 | 9 | Python多线程、多进程 10 | 11 | 网络编程 12 | 13 | 爬虫 -------------------------------------------------------------------------------- /面试资料/README.md: -------------------------------------------------------------------------------- 1 | # 记录准备面试的知识点 2 | 3 | 主要包括: 4 | 5 | 1. [机器学习深度学习结构及相关知识点](./机器学习深度学习结构及相关知识点.md) 6 | 2. [Python核心知识点](./Python核心知识点.md) 7 | 3. [神经网络体系汇总](神经网络体系汇总.png) 8 | 4. [机器学习-激活函数总结](./机器学习-激活函数总结.md) 9 | 10 | -------------------------------------------------------------------------------- /面试资料/code/relu.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-20 10:37:52 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-20 10:38:44 7 | ''' 8 | 9 | import matplotlib.pyplot as plt 10 | import numpy as np 11 | plt.rcParams['font.family']='SimHei' 12 | plt.rcParams['font.sans-serif']=['SimHei'] 13 | 14 | import matplotlib 15 | matplotlib.rcParams['font.family']='SimHei' 16 | matplotlib.rcParams['font.sans-serif']=['SimHei'] 17 | 18 | x=np.linspace(-2,2,100) 19 | y=x*(x>0) 20 | plt.xlabel('x') 21 | plt.ylabel('y') 22 | plt.title("Relu function and its derivative image") 23 | plt.plot(x,y,color='r',label="Relu") 24 | 25 | x=np.linspace(-2,0) 26 | y=np.linspace(0,0) 27 | plt.plot(x,y,color='b') 28 | 29 | x=np.linspace(0,2) 30 | y=np.linspace(1,1) 31 | plt.plot(x,y,color='b',label="derivative") 32 | 33 | plt.legend() 34 | 35 | plt.show() 36 | -------------------------------------------------------------------------------- /面试资料/code/sigmoid.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-20 10:33:48 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-20 10:36:34 7 | ''' 8 | import matplotlib.pyplot as plt 9 | import numpy as np 10 | plt.rcParams['font.family']='SimHei' 11 | plt.rcParams['font.sans-serif']=['SimHei'] 12 | 13 | import matplotlib 14 | matplotlib.rcParams['font.family']='SimHei' 15 | matplotlib.rcParams['font.sans-serif']=['SimHei'] 16 | 17 | x=np.linspace(-10,10,100) 18 | y=1/(1+np.exp(-x)) 19 | plt.xlabel("x") 20 | plt.ylabel("y") 21 | plt.title("sigmoid function and its derivative image") 22 | plt.plot(x,y,color='r',label="sigmoid") 23 | y=np.exp(-x)/pow((1+np.exp(-x)),2) 24 | plt.plot(x,y,color='b',label="derivative") 25 | plt.legend()#将plot标签里面的图注印上去 26 | plt.show() 27 | -------------------------------------------------------------------------------- /面试资料/code/tanh.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @Descripttion: 3 | @Author: daxiong 4 | @Date: 2019-08-20 10:36:44 5 | @LastEditors: daxiong 6 | @LastEditTime: 2019-08-20 10:37:39 7 | ''' 8 | 9 | import matplotlib.pyplot as plt 10 | import numpy as np 11 | plt.rcParams['font.family']='SimHei' 12 | plt.rcParams['font.sans-serif']=['SimHei'] 13 | 14 | import matplotlib 15 | matplotlib.rcParams['font.family']='SimHei' 16 | matplotlib.rcParams['font.sans-serif']=['SimHei'] 17 | 18 | x=np.linspace(-10,10,100) 19 | y=(1-np.exp(-2*x))/(1+np.exp(-2*x)) 20 | plt.xlabel('x') 21 | plt.ylabel('y') 22 | plt.title("Tanh function and its derivative image") 23 | plt.plot(x,y,color='r',label='Tanh') 24 | y=1-pow((1-np.exp(-2*x))/(1+np.exp(-2*x)),2) 25 | plt.plot(x,y,color='b',label='derivative') 26 | plt.legend() 27 | plt.show() -------------------------------------------------------------------------------- /面试资料/offer选择.md: -------------------------------------------------------------------------------- 1 | # offer选择 2 | 3 | 4 | 5 | | - | 地点/分数 | 工资/分数 | 技术上想去程度/分数 | 打分 | 6 | | :--: | :-------: | :-------: | :-----------------: | :--: | 7 | | 思科 | 杭州/10 | 25/5 | 10 | 25 | 8 | | 招银 | 杭州/10 | 27/7 | 7 | 24 | 9 | | 商汤 | 北京/2 | 33/10 | 3 | 15 | 10 | | 百度 | 北京/2 | 25/5 | 5 | 12 | 11 | | | | | | | 12 | 13 | 14 | 15 | | | 地点/分数 | 工资/分数 | 技术扩展分数 | 打分 | 16 | | :----: | :-------: | :-------: | :----------: | :--: | 17 | | 美团 | 北京 | 35.6 | 强 | | 18 | | 绿盟 | 北京 | 32.2 | 强 | | 19 | | 之江 | 杭州 | 24 | 中 | | 20 | | 杭研院 | 杭州 | | 中 | | 21 | | 卡中心 | 上海 | | 中 | | 22 | | | | | | | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /面试资料/各种类型算法及其应用场景.md: -------------------------------------------------------------------------------- 1 | ## 各种类型算法及其应用场景 2 | 3 | ## 0x1 监督学习 4 | 5 | 有标签; 6 | 7 | 8 | 9 | ## 0x2 无监督学习 10 | 11 | 无标签; 12 | 13 | 14 | 15 | ## 0x3 半监督学习 16 | 17 | 部分有标签; 18 | 19 | ## 0x4 强化学习 20 | 21 | 没有标签,只有一个reward,相当于label,但是是有延时的; 22 | 23 | 24 | 25 | ## 0x5 迁移学习 26 | 27 | 将学习的模型迁移到类似的场景中; 28 | 29 | 比如,学会了如何识别中国人,拿来识别外国人,或者在冬天识别的场景,拿来夏天用等等。 30 | 31 | 32 | 33 | ## 0x6 主动学习 34 | 35 | **主动学习方法一般可以分为两部分: 学习引擎和选择引擎。学习引擎维护一个基准分类器,并使用监督学习算法对系统提供的已标注样例进行学习从而使该分类器的性能提高,而选择引擎负责运行样例选择算法选择一个未标注的样例并将其交由人类专家进行标注,再将标注后的样例加入到已标注样例集中。学习引擎和选择引擎交替工作,经过多次循环,基准分类器的性能逐渐提高,当满足预设条件时,过程终止。** 36 | 37 | 样例选择算法: 38 | 39 | 参考:https://www.cnblogs.com/hust-yingjie/p/8522307.html 40 | 41 | ![神经网络体系汇总](./神经网络体系汇总.png) 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /面试资料/常识知识点杂乱小结.md: -------------------------------------------------------------------------------- 1 | # 常识知识点杂乱小结 2 | 3 | 后续会将此小结的点放到对应的框架上,此小姐仅记录日常遇到的小知识点。 4 | 5 | 6 | 7 | *先验概率:是指根据以往经验和分析得到的概率*,**我们人在未知条件下对事件发生可能性猜测的数学表示**! 8 | 9 | *后验概率:**事情已经发生,要求这件事情发生的原因是由某个因素引起的可能性的大小***。(果因概率,即产生的这个结果是由于这个因产生的概率有多大) 10 | 11 | $P(A/B) = \frac{P(B/A)*P(A)}{P(B)}$ 12 | 13 | 这里: 14 | 15 | > 后验概率是$P(A/B)$,意思是现在B已经发生了,而发生B这件事是由A引起的概率有多大。 16 | > 17 | > 先验概率是$P(A)$,这里A发生的概率是我们猜测的,是由经验得到的。比如掷骰子,1出现的概率是1/6。 18 | > 19 | > 类条件概率$P(B/A)$,表示每种概率的分布概率 20 | 21 | 这里给出一个比较形象的公式: 22 | 23 | $P(原因1/结果) = \frac{P(原因1导致结果)}{P(结果)} =\frac{P(结果/原因1)*(P(原因1))}{P(结果)}$ 24 | 25 | 假设产生这个结果只有K个可能的原因,那么,结果的概率又可以写为: 26 | 27 | $P(结果) = P(结果/原因1)*P(原因1) + P(结果/原因2)*P(原因2) + ... +P(结果/原因k)*P(原因k)$ 28 | 29 | 这里,$P(原因1/结果) $为后验概率,$P(原因1)$为先验概率。 30 | 31 | **"概率论只不过是把常识用数学公式表达了出来"---拉普拉斯** 32 | 33 | 34 | 35 | 误差(Error):**预测结果和真实结果之间的差值**。 36 | 37 | 偏差(Bias):在**训练集上的误差叫做偏差**,也就是评估模型在训练集上的表现。 38 | 39 | 方差(Variance):**训练集和测试集上的差异叫方差**,也就是评估模型训练好之后,在测试集上的表现。 40 | 41 | 过拟合(Overfitting):在训练集上效果特别好,在测试集上效果不好;也就是低偏差,高方差。也就是泛化能力差。 42 | 43 | 欠拟合(Underfitting):在训练集和测试集上效果都不好;也就是高偏差,低方差。也就是拟合数据的能力差。 44 | 45 | 过拟合解决办法:设计更加简单的模型、增加模型的训练数据、正则化(损失函数后面加L2等)、使用Dropout层(随机使神经元失效)、调整超参数、提前结束训练、尝试其它模型等; 46 | 47 | 欠拟合解决办法:增加模型的训练数据、增加模型的深度和复杂度、增加迭代次数、更好的优化函数、调整超参数。 48 | 49 | 50 | 51 | 训练集:相当于平时的学习,可以不断的学习新的知识。训练集在我们模型的过程中起的作用就是**更新模型的参数**,用以获得更好的性能,其行为表现就是让我们以为模型掌握了相关的知识(规律) 52 | 53 | 验证集:相当于模拟考试,可以继续巩固学习的知识,是否是**学习到的和真实的有偏差**。验证集就是为了**调整我们模型的超参数(神经元的数量、迭代的次数、序列长度等等)**,这些超参数在某一次的学习迭代中是没有办法改变的。 54 | 55 | 测试集:相当于高考,这时候已经不能再学习和巩固,只能得到**最终的学习结果和真实结果的差异值**。不会有反馈,最终评价模型效果的集合。 56 | 57 | 58 | 59 | 感知机可以理解为单层的神经网络 60 | 多层的神经网络叫做深度学习 61 | 决策树解决的是无非线性因素的分类 62 | 随机森林是多决策树 63 | KNN是用最小距离法做聚类的 64 | 贝叶斯是根据先验概率去做统计的算法 65 | 马尔可夫可以理解为多个贝叶斯概率串起来解决状态转移的概率 66 | 支持向量机是利用线性算法去拟合分割平面的分类算法 67 | 逻辑回归解决的是连续型拟合(分类相当于离散型) 68 | 梯度下降并不是机器学习的算法,而是神经网络的反向传播算法,用来调整权重参数 69 | 最小二乘法也是类似的,它也是一种参数估计的算法 70 | 深度学习即可做生成(升维,解码),也可以做判别(或者叫分类,降维,编码) 71 | 72 | 73 | 74 | [回归与分类的区别](https://www.cnblogs.com/aurorablog/p/9034491.html) 75 | 76 | 1)输出数据的类型 77 | 78 | 分类输出的数据类型是离散数据,也就是分类的标签。比如我们前面通过学生学习预测考试是否通过,这里的预测结果是考试通过,或者不通过,这2种离散数据。 79 | 80 | 回归输出的是连续数据类型。比如我们通过学习时间预测学生的考试分数,这里的预测结果分数,是连续数据。 81 | 82 | 2)第2个区别是我们想要通过机器学习算法得到什么? 83 | 84 | 分类算法得到是一个决策面,用于对数据集中的数据进行分类。 85 | 86 | 回归算法得到是一个最优拟合线,这个线条可以最好的接近数据集中的各个点。 87 | 88 | 3)第3个区别是对模型的评估指标不一样 89 | 90 | 在监督分类中,我们我们通常会使用正确率作为为指标,也就是预测结果中分类正确数据占总数据的比例 91 | 92 | 在回归中,我们用决定系数R平方来评估模型的好坏。R平方表示有多少百分比的y波动被回归线描述。 93 | 94 | 95 | 96 | 均方误差是回归问题中最常用的性能量度。逻辑回归就是分类;线性回归是回归。 97 | 98 | 99 | 100 | 基于均方误差最小化来进行模型求解的方法称为"最小二乘法";求解的过程称为最小二乘的“参数估计” 101 | 102 | 103 | 104 | 神经网络比较适用于特征表示较差的数据,比如图像;但如果一个数据特征表示比较好,则可以直接使用机器学习 105 | 106 | 107 | 108 | 损失函数:一个样本的误差(误差就是预测值合真实值之间的差距) 109 | 110 | 代价函数:整个训练集上所有样本的误差集合的平均 111 | 112 | 目标函数:代价函数+正则化项 113 | 114 | 115 | 116 | 逻辑回归里面如果使用均方误差的话,当学习参数的时候,这个问题可能会变成非凸问题,就会导致局部最优。 -------------------------------------------------------------------------------- /面试资料/损失函数总结.md: -------------------------------------------------------------------------------- 1 | # 损失函数总结 2 | 3 | ## 0x1 概念解析 4 | 5 | 损失函数(Loss Function )是定义在**单个样本**上的,算的是一个样本的误差。 6 | 7 | 代价函数(Cost Function )是定义在**整个训练集**上的,是所有样本误差的平均,也就是损失函数的平均。有时候大家将代价函数和损失函数等价。 8 | 9 | 目标函数(Object Function)定义为:最终需要优化的函数。等于经验风险+结构风险(也就是**Cost Function + 正则化项**)。**经验损失函数反映的是预测结果和实际结果之间的差别**,**结构风险损失函数则是经验风险损失函数加上的正则项**(L0、L1(Lasso)、L2(Ridge))。 10 | 11 | 风险函数(Risk Function)是损失函数的期望。 12 | 13 | 通常而言:目标函数是最大化或者最小化,而代价函数是最小化 14 | 15 | 我们最终的优化函数(目标函数)是: 16 | $$ 17 | \theta ^*=arg \mathop{min}\limits_{\theta} \frac{1}{N}\sum_{i=1}^NL(y_i,f(x_i;\theta))+\lambda\Phi(\theta) 18 | $$ 19 | 也即是最优化经验风险加结构风险 20 | 21 | 代价函数的性质: 22 | 23 | 1. 对每种算法,代价函数不唯一 24 | 2. 代价函数是参数的函数 25 | 3. 总的代价函数可以用来评价模型的好坏 26 | 4. 代价函数是一个标量 27 | 28 | 29 | 30 | ## 0x2 log对数损失函数(逻辑回归) 31 | 32 | log损失函数的标准形式: 33 | $$ 34 | L(Y,P(Y|X))=-logP(Y|X) 35 | $$ 36 | 在逻辑回归的推导中,它假设样本服从伯努利分布(0-1分布),然后求得满足该分布的似然函数,接着取对数求极值 37 | 38 | 把极大化当做是一种思想,进而推导出它的经验风险函数为:最小化负的似然函数。从损失函数的视角来看,它就成了log损失函数 39 | 40 | 取对数是为了方便计算极大似然估计,因为在MLE中,直接求导比较困难,所以通常都是先取对数再求导找极值点。损失函数L(Y, P(Y|X))表达的是样本X在分类Y的情况下,使概率P(Y|X)达到最大值(换言之,就是利用已知的样本分布,找到最有可能(即最大概率)导致这种分布的参数值;或者说什么样的参数才能使我们观测到目前这组数据的概率最大)。因为log函数是单调递增的,所以logP(Y|X)也会达到最大值 41 | 42 | 因此在前面加上负号之后,就等价于最小化损失函数了 43 | 44 | 交叉熵刻画两个概率分布之间的距离。 45 | 46 | ## 0x3 平方损失函数(最小二乘法,Ordinary Least Squares) 47 | 48 | 最小二乘的基本原则是:最优拟合直线应该是使各点到回归直线的距离和最小的直线,即平方和最小。 49 | 50 | 换言之,OLS是基于距离的,而这个距离就是我们用的最多的**欧几里得距离** 51 | 52 | 为什么它会选择使用欧式距离作为误差度量呢(即**Mean squared error, MSE**),主要有以下几个原因: 53 | 54 | * 简单,计算方便; 55 | 56 | * 欧氏距离是一种很好的相似性度量标准; 57 | 58 | * 在不同的表示域变换后特征性质不变。 59 | 60 | 平方损失(Square loss)的标准形式如下: 61 | 62 | $$ 63 | L(Y,f(X)) = (Y-f(X))^2 64 | $$ 65 | 当样本个数为N时,此时的损失函数变为: 66 | $$ 67 | L(Y,f(X))=\frac{1}{N}\sum_{i=1}^N(Y-f(X))^2 68 | $$ 69 | Y-f(X)表示的是残差,整个式子表示的是残差的平方和,而我们的目的就是最小化这个目标函数值(注:该式子未加入正则项),也就是最小化残差的平方和(residual sum of squares,RSS)。 70 | 71 | 而在实际应用中,通常会使用均方差(MSE)作为一项衡量指标,公式如下: 72 | 73 | $$ 74 | MSE=\frac{1}{N}\sum_{i=1}^N(\tilde{Y_i}-f(X_i))^2 75 | $$ 76 | 77 | ## 0x4 指数损失(Adaboost) 78 | 79 | 常用在Adaboost之中 80 | 81 | 在Adaboost中,经过m此迭代之后,可以得到fm(x): 82 | 83 | $$ 84 | f_m(x)=f_{m-1}(x)+\alpha_mG_m(x) 85 | $$ 86 | Adaboost每次迭代时的目的是为了找到最小化下列式子时的参数α 和G: 87 | 88 | $$ 89 | arg \mathop{min}\limits_{\alpha,G}=\sum_{i=1}^Nexp[-y_i(f_{m-1}(x_i))+\alpha G(x_i)] 90 | $$ 91 | 而指数损失函数(exp-loss)的标准形式如下 92 | $$ 93 | L(y,f(X))=exp[-yf(x)] 94 | $$ 95 | 可以看出,Adaboost的目标式子就是指数损失,在给定n个样本的情况下,Adaboost的损失函数为: 96 | 97 | $$ 98 | L(y,f(X))=\frac{1}{N}\sum_{i=1}^Nexp[-y_if(x_i)] 99 | $$ 100 | 101 | ## 0x5 Hinge函数损失(SVM) 102 | 103 | Hinge 损失函数的标准形式 104 | $$ 105 | L(y)=max(0,1-y\tilde{y}),y=\pm1 106 | $$ 107 | ^为预测值,在-1到1之间,y为目标值(-1或1) 108 | 109 | 110 | 111 | ## 其它损失函数 112 | 113 | 除了以上这几种损失函数,常用的还有:0-1损失是指,预测值和目标值不相等为1,否则为0: 114 | 115 | 0-1损失函数:(注意是不相等时为1,相等时为0) 116 | $$ 117 | L(Y,f(X))= 118 | \begin{cases} 119 | 1, y\not=f(X)\\ 120 | 0, y=f(X) 121 | \end{cases} 122 | $$ 123 | 绝对值损失函数 124 | $$ 125 | L(Y,f(X))=|Y-f(X)| 126 | $$ 127 | 损失函数汇总: 128 | 129 | ![损失函数](./Images/损失函数.png) 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /面试资料/机器学习-激活函数总结.md: -------------------------------------------------------------------------------- 1 | # 机器学习-激活函数总结 2 | 3 | ## 0x1 为什么要引入激活函数 4 | 5 | 如果没有激活函数,那么每一层其实本质上就是一个线性函数,与没有隐藏层效果相当,这样就与最原始的感知机一样了,这样带来的一个最严重的问题就是网络的**表达能力**(也可以理解为逼近的能力)十分有限, **无法解决线性不可分的问题**。 6 | 7 | 正是因为线性函数的网络表达能力有限,所以引入了**非线性函数**作为激励函数,这样深层次的神经网络模型表达能力就会更加强大。(这样不再是简单的线性组合,而是基本上可以拟合或逼近任意函数),**非线形的激活函数就能够解决线性不可分的问题了**。 8 | 9 | 10 | 11 | ## 0x2 为什么引入Relu 12 | 13 | 1. 采用sigmoid等函数,算激活函数时(指数运算),**计算量大**,反向传播求误差梯度时,求导涉及除法,计算量相对大,而采用Relu激活函数,整个过程的计算量节省很多。 14 | 15 | 2. 对于深层网络,sigmoid函数反向传播时,很容易就会出现**梯度消失**的情况(在sigmoid接近饱和区时,变换太缓慢,导数趋于0),从而无法完成深层网络的训练。 16 | 17 | 3. Relu会使一部分神经元的输出为0,这样就造成了网络的**稀疏性**,并且减少了参数的相互依存关系,缓解了过拟合问题的发生(以及一些人的生物解释balabala)。 18 | 19 | 20 | 21 | ## 0x3 sigmoid激活函数 22 | 23 | sigmoid常用的非线性激活函数,公式为:$f(x) = \frac{1}{1+e^{-x}}$ 24 | 25 | sidmoid函数图像和导函数图像如下: 26 | 27 | ![sigmoid](./Images/sigmoid.png) 28 | 29 | 特点:它能够把输入的连续实值变换为0和1之间的输出,特别的,如果是非常大的负数,那么输出就是0;如果是非常大的正数,输出就是1. 30 | 31 | 缺点1. 在深度神经网络中梯度反向传递时导致**梯度爆炸和梯度消失**,其中梯度爆炸发生的概率非常小,而梯度消失发生的概率比较大。如果我们初始化神经网络的权值为、[0,1]之间的随机值,由反向传播算法的数学推导可知,梯度从后向前传播时,每传递一层梯度值都会减小为原来的0.25倍,如果神经网络隐层特别多,那么梯度在穿过多层后将变得非常小接近于0,即出现梯度消失现象;当网络权值初始化为 (1,+∞) 区间内的值,则会出现梯度爆炸情况。**x很大的时候,y的值区别不是很大,就会出现梯度消失的问题。** 32 | 33 | 缺点2. **Sigmoid 的 output 不是0均值**(即zero-centered)。这是不可取的,因为这会导致后一层的神经元将得到上一层输出的非0均值的信号作为输入。 产生的一个结果就是:如x>0,$f = w^Tx + b$,那么对w求局部梯度则都为正,这样在反向传播的过程中w要么都往正方向更新,要么都往负方向更新,导致有一种捆绑的效果,使得收敛缓慢。 当然了,如果按batch去训练,那么那个batch可能得到不同的信号,所以这个问题还是可以缓解一下的。因此,非0均值这个问题虽然会产生一些不好的影响,不过跟上面提到的梯度消失问题相比还是要好很多的。 34 | 35 | 缺点3. 其解析式中含有幂运算,计算机求解时相对来讲比较耗时。对于规模比较大的深度网络,这会较大地增**加训练时间**。 36 | 37 | 38 | 39 | ## 0x4 tanh激活函数 40 | 41 | tanh激活函数为:$tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}$ 42 | 43 | tanh函数图像和导函数图像如下: 44 | 45 | ![](./Images/tanh.png) 46 | 47 | tanh读作Hyperbolic Tangent,**它解决了Sigmoid函数的不是zero-centered输出问题** 48 | 49 | 然而,**梯度消失(gradient vanishing)的问题和幂运算的**问题仍然存在。 50 | 51 | 52 | 53 | ## 0x5 ReLU激活函数 54 | 55 | Relu激活函数为:$Relu = max(0, x)$ 56 | 57 | Relu函数图像和导函数图像如下: 58 | 59 | ![](./Images/relu.png) 60 | 61 | Relu激活函数的优点: 62 | 63 | 1. 在正区间内解决了梯度消失的问题。 64 | 2. 计算速度很快,只需要判断输入是否大于0 65 | 3. 收敛速度远快于sigmoid和tanh。 66 | 67 | Relu激活函数的问题: 68 | 69 | 1. ReLU的输出不是zero-centered 70 | 71 | 2. Dead ReLU Problem,指的是**某些神经元可能永远不会被激活**,导致相应的参数永远不能被更新。有两个主要原因可能导致这种情况产生: (1) **非常不幸的参数初始化**,这种情况比较少见 (2) **learning rate太高**导致在训练过程中参数更新太大,不幸使网络进入这种状态。解决方法是可以采用Xavier初始化方法,以及避免将learning rate设置太大或使用adagrad等自动调节learning rate的算法。 72 | 73 | 尽管存在这两个问题,ReLU目前仍是最常用的activation function,在搭建人工神经网络的时候推荐优先尝试! 74 | 75 | 76 | 77 | ## 0x6 PReLU激活函数 78 | 79 | PReLU是Leaky ReLU的一个变体,叫做**参数化修正线性单元**,函数表达式为:$f(x) = max(\alpha x, x)$ 80 | 81 | PRelu函数图像和导函数图像如下:在下左图的左边部分,其斜率$\alpha$是一个非常小的值,接近于0,所以看起来像平的。 82 | 83 | ![](./Images/PReLU.png) 84 | 85 | PRelu激活函数的优点: 86 | 87 | **解决了ReLU某些神经元无法被激活的问题。** 88 | 89 | 90 | 91 | ## 0x7 RReLU激活函数 92 | 93 | RReLu也是Leaky ReLU的一个变体,叫做**随机修正线性单元**,激活函数的表达式为: 94 | $$ 95 | y_{ji} 96 | \begin{cases} 97 | x_{ji}, &if\ x_{ji}\ \ge \ 0\\ 98 | x_{ji}x_{ji}, &otherwise 99 | \end{cases} 100 | 101 | where \ a_{ji}\sim\ U(l,u), l < u \ and\ l\ ,u \in[0,1] 102 | $$ 103 | ReLU、ReLU、PReLU、RReLU的对比图如下: 104 | 105 | ![](./Images/ReLU_PReLU_RReLU.jpeg) 106 | 107 | 1. PReLU中的ai是根据数据变化的; 108 | 2. Leaky ReLU中的ai是固定的 109 | 3. RReLU中的aji是一个在一个给定的范围内随机抽取的值,这个值在测试环节就会固定下来。 110 | 111 | 112 | 113 | ## 0x8 ELUs激活函数 114 | 115 | ELUs(Exponential Linear Units)激活函数的表达式为: 116 | $$ 117 | f(x) 118 | \begin{cases} 119 | x, &if\ x\ >\ 0\\ 120 | \alpha(e^x - 1), &otherwise 121 | \end{cases} 122 | $$ 123 | ELUs函数图像和导函数图像如下 124 | 125 | ![](./Images/ELUs.png) 126 | 127 | ELUs基本具备ReLu的所有优点,以及: 128 | 129 | 1. 不会有Dead ReLu的问题 130 | 2. 输出的均值接近于0, zero-centered 131 | 132 | ## 0x9 Maxout激活函数 133 | 134 | Maxout是深度学习网络中的一层网络,就像池化层、卷积层一样等,我们可以把maxout 看成是网络的激活函数层,我们假设网络某一层的输入特征向量为:X=(x1,x2,……xd),也就是我们输入是d个神经元 135 | 136 | maxout计算公式为:$h_i(x) = \max_{j\in[i, k]} z_{ij}$ 137 | 138 | 其中:$z_{ij} = x^TW_{...ij} + b_{ij}$ 139 | 140 | 141 | 142 | ## 0x10 如何选择激活函数 143 | 144 | 1. 深度学习往往需要大量时间来处理大量数据,模型的收敛速度是尤为重要的。所以,总体上来讲,训练深度学习网络**尽量使用zero-centered**数据 (可以经过数据预处理实现) 和zero-centered输出。所以要尽量选择输出具有zero-centered特点的激活函数以加快模型的收敛速度。 145 | 2. 如果使用 ReLU,那么一定要小**心设置 learning rate**,而且要注意不要让网络出现很多 “dead” 神经元,如果这个问题不好解决,那么可以试试 Leaky ReLU、PReLU 或者 Maxout. 146 | 3. **最好不要用 sigmoid,你可以试试 tanh**,不过可以预期它的效果会比不上 ReLU 和 Maxout. 147 | 148 | 149 | 150 | ## 0x11 激活函数总结 151 | 152 | | 激活函数 | 优点 | 缺点 | 备注 | 153 | | :------: | :----------------------------------------------------------- | :----------------------------------------------------------- | -------------- | 154 | | sigmoid | 1. 便于求导的平滑函数
2. 能压缩数据,保证数据幅度
3.适合相前传播 | 1. 梯度消失
2.输出不是0均值
3.幂运算耗时 | 饱和激活函数 | 155 | | tanh | 1. 解决了sigmoid的输出不是0均值的问题 | 1.梯度消失
2.幂运算耗时 | 饱和激活函数 | 156 | | ReLU | 1. 速度快
2.计算复杂度低
3.适用于向后传播 | 1. 输出不是0均值
2.神经元坏死现象
3. ReLU不会对数据进行压缩 | 非饱和激活函数 | 157 | | PReLU | 1. 解决了神经元坏死(Dead ReLU)现象 | | 非饱和激活函数 | 158 | | RReLU | | | 非饱和激活函数 | 159 | | ELUs | 1. 有ReLU的所有优点
2.不存在神经元坏死(Dead ReLU)现象
3.输出为0均值 | 1.计算量大 | 非饱和激活函数 | 160 | | maxout | 1. 具有ReLU的所有优点,线性、不饱和性。
2.不存在神经元坏死(Dead ReLU)现象 | 1. 参数量巨大 | 非饱和激活函数 | 161 | 162 | 非饱和激活函数优点:**能解决梯度消失问题,收敛速度快**。 163 | 164 | 饱和性含义是说,当自变量x的值太大,其导函数接近于0,导致梯度消失。所以sigmoig和tanh都存在梯度消失的问题。 165 | 166 | 167 | 168 | 参考1:https://blog.csdn.net/weixin_43077261/article/details/97285284 169 | 170 | 参考2:https://blog.csdn.net/tyhj_sf/article/details/79932893 171 | 172 | 参考3: https://www.cnblogs.com/XDU-Lakers/p/10557496.html 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /面试资料/机器学习_SVM 学习笔记.md: -------------------------------------------------------------------------------- 1 | # SVM 学习笔记 2 | 3 | SVM是从数学理论开始的,所以比较有保证,而且效果比较好。 4 | 5 | Key Idea: 6 | 7 | > 1. 所找的超平面,使得间隔最远。 8 | 9 | 10 | 11 | SVM的目标: 12 | 13 | -------------------------------------------------------------------------------- /面试资料/机器学习深度学习结构及相关知识点.md: -------------------------------------------------------------------------------- 1 | # 梯度迭代总结整理机器学习算法相关知识 2 | 3 | 按照常考察的来,不过最重要的还是逐步理解学习 4 | 5 | 6 | 7 | 激活函数有哪些(公式,图像,优势),作用是什么 8 | 9 | 损失函数都有哪些(函数,图像,含义,优势),交叉熵等,作用是什么 10 | 11 | 反向传播算法有哪些(公式,含义,优势),Adam等,作用是什么 12 | 13 | 生成式和判别式分别是什么意思,有哪些代表方法。联合概率条件概率等 14 | 15 | 机器(深度)学习的类型有哪些,基本含义和应用场景在哪,监督学习等 16 | 17 | 防止过拟合的方法有哪些,优缺点 18 | 19 | 超级参数有哪些 20 | 21 | 正则化的方法有哪些,有什么作用。BN(Batch Normalization) 22 | 23 | 深度学习模型每一层主要用大的函数和功能是啥,CNN,LSTM等,以及如何反向传播 24 | 25 | 推荐学习的主要方法和优缺点 26 | 27 | KNN和K-means的区别,最大的区别在于语料的区别。KNN是分类算法,K-means是聚类算法。 28 | 29 | 逐步更新迭代.... 30 | 31 | **各个算法主要的模块,KNN,SVM,决策树,Adaboost。需要原理,总结,以及代码实现**,这部分在后期逐步完善 32 | 33 | 34 | 35 | CNN使用RELU,而不使用之前常使用的双曲正切函数或者S型函数等非线性方程的原因是:RELU能在保证准确率不发生明显改变的情况下加快训练的速度(因为计算速度增加),也能减轻梯度降低的问题。 36 | 37 | 最大池化:减少了参数,可以防止过拟合。Dropout 层只能在训练中使用,而不能用于测试过程,这是很重要的一点。 -------------------------------------------------------------------------------- /面试资料/梯度下降法.md: -------------------------------------------------------------------------------- 1 | # 梯度下降法的三种形式 2 | 3 | ## 0x1 批量梯度下降(BGD) 4 | 5 | 批量梯度下降法(Batch Gradient Descent, BGD)是梯度下降的最原始方法,**核心点在于每次都使用所有的样本来更新参数**,最小化损失函数,如果只有一个极小值,那么BGD是考虑了所有的数据,朝着代价最小的方向运动,缺点在于**如果样本值很大的话,更新速度很慢**。 6 | $$ 7 | \theta = \theta - \eta.\nabla J(\theta) 8 | $$ 9 | 其中,$$J(\theta)$$为整个数据集上的代价函数,$$\theta$$为我们要更新的参数; 10 | 11 | ## 0x2 随机梯度下降(SGD) 12 | 13 | 随机梯度下降(Stochastic Gradient Descent, SGD),**使用每个样本的损失函数来更新参数**。 14 | 15 | 正是由于只考虑了一个样本点,所以会大大的加快训练数据,也就是弥补了BGD训练速度慢的问题。然而,如果训练数据中噪声点太多的话,那么每一次利用噪声点进行更新的过程中,就不一定是朝着极小值的方向更新,但由于更新多轮,整体方向上还是超着极小值的方向更新,又提高了速度。 16 | $$ 17 | \theta = \theta - \eta.\nabla_{\theta} J(\theta; x^i;y^i) 18 | $$ 19 | 这里,就是只是根据其中的某一个样本i更新参数; 20 | 21 | ## 0x3 小批量梯度下降(MBGD) 22 | 23 | 小批量梯度下降(Mini-batch Gradient Descent, MBGD),为了解决BGD的训练慢和SGD的准确率的问题,提出了MBGD,**每次使用一个batch的数量进行更新参数**,不同的问题batch是不一样的。 24 | $$ 25 | \theta = \theta - \eta.\nabla_{\theta}J(\theta;x^{i:i+n};y^{i:i+n}) 26 | $$ 27 | 这里,是根据i-i+n之间的样本来更新参数的; 28 | 29 | 需要注意的是,这三种梯度学习方法都是使用的相同的学习率,需要预先设置学习率,而且整个计算的过程中不改变,这里会产生如下的问题: 30 | 31 | 1):选择一个合适的学习率是非常困难的事情。学习率较小,收敛速度将会非常慢;而学习率较大时,收敛过程将会变得非常抖动,而且有可能不能收敛到最优。 32 | 33 | 2):预先制定学习率变化规则。比如,计算30轮之后,学习率减半。但是这种方式需要预先定义学习率变化的规则,而规则的准确率在训练过程中并不能保证。 34 | 35 | 3):上述三种算法针对所有数据采用相同的学习速率,但是当我们的数据非常稀疏的时候,我们可能不希望所有数据都以相同的方式进行梯度更新,而是对这种极少的特征进行一次大的更新。 36 | 37 | 4):高度非凸函数普遍出现在神经网络中,在优化这类函数时,另一个关键的挑战是使函数避免陷入无数次优的局部最小值。 38 | 39 | 40 | 41 | 参考:https://www.jianshu.com/p/0acd30a23e4e -------------------------------------------------------------------------------- /面试资料/深度学习优化器.md: -------------------------------------------------------------------------------- 1 | # 深度学习优化器 2 | 3 | -------------------------------------------------------------------------------- /面试资料/神经网络体系汇总.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/88daxiong/Interview/e604dbb29f251a267ba45673f0ad25b930de5fb6/面试资料/神经网络体系汇总.png -------------------------------------------------------------------------------- /面试资料/问题解决步骤.md: -------------------------------------------------------------------------------- 1 | # 解题思路与步骤 2 | 3 | 首先,面对一个具体的实际问题,我们不能一下子就进入到模型的构建和训练当中,我们首先得明白整体的框架,然后一步一步的做每一个步骤,这样才能解决实际的问题。 4 | 5 | 一般来说,遇到一个问题,我们首先需要明确: 6 | 7 | 1. 这个问题的目标是什么? 8 | 2. 然后,数据有没有标签(有监督还是无监督),这是一个分类任务和回归任务?学习的方式是如何的。 -------------------------------------------------------------------------------- /面试问题及答案汇总/全知科技-算法工程师_1面.md: -------------------------------------------------------------------------------- 1 | # 全知科技-算法工程师1面 2 | 3 | ## 0x1 项目里面的CNN结构是什么样的?为什么要这么选?详细说一下卷积层、池化层、全连接层的作用。说一下在CNN反向传播的时候,**全连接层和卷积层是如何计算损失向前传播的**。 4 | 5 | 前两个问题可能存粹是因为CNN在图像上的效果比较好,所以这么选。以及为什么这个设计结构,只能简单的回答说这是CNN一个典型的结构,对于这一块我其实也不是特别清楚。 6 | 7 | 一个CNN说的典型结构: *输入→卷积→ReLU→卷积→ReLU→池化→ReLU→卷积→ReLU→池化→全连接* 8 | 9 | ### 1)卷积核作用 10 | 11 | 最后我们训练CNN卷积神经网络,最后训练得出来的东西其实就是这些卷积核的参数。当参数固定了之后,对于一张新的图片,就能判断出是属于什么了。 12 | 13 | 卷积核(Filter)也叫特征标识符,这些特征可以指直边缘,原色,曲线等等。卷积核本质上就是空间或时间上的加权求和。 14 | 15 | ### 2)卷积层 16 | 17 | 卷积层就是一个卷积核扫描后得到的一张图片,一张图片经过多少个卷积核,就会有多少张图片生成 18 | 19 | ## 3)池化层 20 | 21 | Pooling层对于卷积层进行了个一个降维的操作。 Max Pooling是对一个卷积层抽取的特征值取最大的值作为这个层的保留值, 其他值全部抛弃,这个值代表了特征值种最显著的特征。他可以减少模型的参数数量,减少过拟合的问题。 22 | 23 | ### 4)全连接层 24 | 25 | 全连接层起到的是将学到的“分布式特征表示”映射到样本标记空间的作用。完全连接层观察高级特征和哪一分类最为吻合和拥有怎样的特定权重,因此当计算出权重与先前层之间的点积后,你将得到不同分类的正确概率。 26 | 27 | 参考1:https://www.jianshu.com/p/09f35a390ac2 28 | 29 | 参考2:https://blog.csdn.net/lee813/article/details/82141526 30 | 31 | 参考3:https://blog.csdn.net/moyu916/article/details/88627479 32 | 33 | ### 5)池化层反向传播 34 | 35 | 首先需要确定池化后的那个误差值是由原来4*4(池化大小)的哪个区域决定。如果是最大池化,我们只需要记录向前传播中最大值的位置,然后误差放回去即可。如果是平均池化,只需要将池化但愿的误差的平均值放回去原来的子矩阵即可。 36 | 37 | ### 6)卷积层的反向传播 38 | 39 | 核心点,卷积核的权重矩阵需要旋转180度。 40 | 41 | 参考:https://blog.csdn.net/qq_16137569/article/details/81477906 42 | 43 | 44 | 45 | ## 0x2 python的多线程和多进程是如何的,为什么会有多线程这个东西,说一下原理。python的多线程是真的多线程吗?碰到一个具体情况如何判断,两种方式优缺点分别在哪? 46 | 47 | **Python中的多线程没有真正实现多线程**,**GIL**。Python代码的执行由Python虚拟机(解释器)来控制,Python在设计之初就考虑要在主循环中,同时只有一个线程在执行,就像单CPU的系统中运行多个进程那样,内存中可以存放多个程序,但任意时刻,只有一个程序在CPU中运行。同样地,虽然Python解释器可以运行多个线程,只有一个线程在解释器中运行。 48 | 49 | 所以我们的代码是CPU密集型的,那么这个时候的多线程代码很有可能是线程执行的。因为在任意时间只有一个Python解释器来解释Python 字节码。 50 | 51 | 但如果我们的代码是IO密集型的话,这个时候多线程的效率就可以很明显的体现出来了,可以很明显的提高效率,比如python爬虫。 52 | 53 | ## 0x3 分析一下为什么朴素贝叶斯的效果不太好,说一下朴素贝叶斯和决策树随机森林的模型的主要区别。 54 | 55 | 朴素贝叶斯可能主要是基于概率计算的,而我的项目里正负样本差距太大,导致分析的结果差别很大。 56 | 57 | 随机森林和决策树可能主要是机遇信息增益这快比较多,来进行分支判别。 58 | 59 | 60 | 61 | ## 0x4 说一下编译器和解释器的区别 62 | 63 | 解释器:一边编译,一边运行。一段程序在解释器中运行可能会被编译很多遍,因为每次运行这段程序时,都要重新编译,所以开销比较大。(Python,Perl,JavaScript等一些脚本语言) 64 | 65 | **在程序执行时,解释器读取一句源代码之后,先进行词法分析和语法分析,再将源代码转换为解释器能够执行的中间代码(字节码),最后,由解释器将中间代码解释为可执行的机器指令。** 66 | 67 | 编译器:先将源代码编译为不同的CPU可以运行的机器码,在CPU上运行,所以速度很快。流程为: 68 | 69 | **源代码 (source code) → 预处理器 (preprocessor) → 编译器 (compiler) → 目标代码 (object code) → 链接器 (Linker) → 可执行程序 (executables)。** 70 | 71 | 正因为上述的原因,需要匹配不同的CPU架构,所以库文件和操作系统等都要匹配,所以这类语言是不跨平台的(C、C++等)。 72 | 73 | 参考1:https://blog.csdn.net/touzani/article/details/1625760 74 | 75 | 参考2:http://www.opython.com/1355.html 76 | 77 | ## 0x5 说一下生成式和判别式的区别,从数学上说一下 78 | 79 | 生成式模型:生成式模型是对x和y的联合概率p(x,y)进行建模,然后通过贝叶斯公式来求p(y/x),最后选取使得p(y/x)最大的yi作为最后的结果。是**联合概率**。 80 | 81 | 判别式模型:判别式模型会对p(y/x)建模。是**条件概率**。 82 | 83 | 生成式模型算法有:判别式分析,朴素贝叶斯,KNN,混合高斯模型,隐马尔可夫模型(HMM),贝叶斯网络,深度信念网络,马尔可夫随机场。 84 | 85 | 判别式模型算法有:线性回归,逻辑回归,神经网络,SVM,高斯过程,条件随机场,CART 86 | 87 | 参考:https://www.cnblogs.com/kemaswill/p/3427422.html -------------------------------------------------------------------------------- /面试问题及答案汇总/全知科技-算法工程师_2面.md: -------------------------------------------------------------------------------- 1 | # 全知科技2面 2 | 3 | 这算是全知科技的终面了。 4 | 5 | ## 0x1详细介绍项目 6 | 7 | 吧啦吧啦,这里没有问算法的问题,主要是问对项目的把握以及细节。需要对项目的每一个小点都特别熟悉。 8 | 9 | 10 | 11 | ## 0x2 介绍一下以后想做什么,做这件事主要需要哪些能力。 12 | 13 | 这种问题还不知道怎么回答... 14 | 15 | 16 | 17 | ## 0x3 leetcode3 18 | 19 | 给定一个字符串,找出无重复字符的最长子串。然后详细的问了复杂度的计算。 20 | 21 | 主要就是双指针,然后使用滑动窗口。 22 | 23 | ```python 24 | class Solution: 25 | def lengthOfLongestSubstring(self, s: str) -> int: 26 | # 如果字符串s为空,返回0 27 | if not s:return 0 28 | # 保存窗口内字符串 29 | lookup = list() 30 | n = len(s) 31 | # 最大子串长度 32 | max_len = 0 33 | # 当前窗口长度 34 | cur_len = 0 35 | # 遍历字符串s 36 | for i in range(n): 37 | val = s[i] 38 | # 如果该值不在窗口中 39 | if not val in lookup: 40 | # 添加到窗口内 41 | lookup.append(val) 42 | # 当前长度+1 43 | cur_len+=1 44 | # 如果该值在窗口中已存在 45 | else: 46 | # 获取其在窗口中的位置 47 | index = lookup.index(val) 48 | # 移除该位置及之前的字符,相当于上图中的图3到图4 49 | lookup = lookup[index+1:] 50 | lookup.append(val) 51 | # 当前长度更新为窗口长度 52 | cur_len = len(lookup) 53 | # 如果当前长度大于最大长度,更新最大长度值 54 | if cur_len > m 55 | ``` 56 | 57 | 参考:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/solution/hua-dong-chuang-kou-tu-wen-jiang-jie-by-superychen/ 58 | 59 | 60 | 61 | ## 0x3 抛硬币游戏 62 | 63 | 这个问题可以供大家想一想。 64 | 65 | ### 1.0版本 66 | 67 | 第一次抛: 68 | 69 | 如果正面朝上,这个时候你可以选择继续抛第二次,也可以选择拿到2块钱结束。 70 | 71 | 如果反面朝上,游戏结束,你拿不到钱。 72 | 73 | 74 | 75 | 第二次抛: 76 | 77 | 如果正面朝上,这个时候你可以选择继续抛第三次,也可以选择拿到3块钱结束。 78 | 79 | 如果反面朝上,游戏结束,你拿不到钱。 80 | 81 | 。。。 82 | 83 | 第N次抛: 84 | 85 | 如果正面朝上,这个时候你可以选择继续抛第N+1次,也可以选择拿到N块钱结束。 86 | 87 | 如果反面朝上,游戏结束,你拿不到钱。 88 | 89 | 90 | 91 | 问:你愿意花多少钱玩这个游戏。 92 | 93 | 94 | 95 | ### 2.0版本 96 | 97 | 第一次抛: 98 | 99 | 如果正面朝上,这个时候你可以选择继续抛第二次,也可以选择拿到2块钱结束。 100 | 101 | 如果反面朝上,游戏结束,你拿不到钱。 102 | 103 | 104 | 105 | 第二次抛: 106 | 107 | 如果正面朝上,这个时候你可以选择继续抛第三次,也可以选择拿到4块钱结束。 108 | 109 | 如果反面朝上,游戏结束,你拿不到钱。 110 | 111 | 。。。 112 | 113 | 第N次抛: 114 | 115 | 如果正面朝上,这个时候你可以选择继续抛第N+1次,也可以选择拿到$2^N$块钱结束。 116 | 117 | 如果反面朝上,游戏结束,你拿不到钱。 118 | 119 | 120 | 121 | 问:你愿意花多少钱玩这个游戏。 122 | 123 | 124 | 125 | 126 | 127 | 我的想法:每个问题都需要算最大期望,然后玩几次很重要。 -------------------------------------------------------------------------------- /面试问题及答案汇总/海康威视-AI算法工程师.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # 海康威视-AI算法工程师 4 | 5 | 海康威视主要是做视频监控,所以会大量的运用到图片的处理技术。所以所问的问题也基本和图片的一些原理和操作相关,然后是与深度学习结合起来做检测识别,猜测主要也是CNN. 6 | 7 | 另外,主要是用C++来实现相关的算法问题。所以对项目、算法和Python不是特别看重。 8 | 9 | ## 1. 腐蚀和膨胀 10 | 11 | 直观上来看,腐蚀和膨胀一个是缩小了图像,另一个增大了图像。具体来说; 12 | 13 | 有一个图像X,有一个结构元素B,B平移的点记作a,如果: 14 | 15 | 1、B平移后的元$B^v$**包含于**X,那么a的集合则称作X腐蚀后的结果。 16 | 17 | 2、B平移后的元$B^v$**击中**X,那么a的集合则称作X膨胀后的结果。 18 | 19 | 参考: 20 | 21 | https://blog.csdn.net/junpengxue/article/details/79958651 22 | 23 | https://blog.csdn.net/zqx951102/article/details/82997588 24 | 25 | ## 2. 图像的缩放算法 26 | 27 | ### 1、最近邻算法 28 | 29 | 在待求像素的(待插值图的)四邻像素中,将距离待求像素最近的邻像素灰度赋给待求像素。 30 | 31 | **优点:**最常见,最通用的算法之一,计算量很小,算法简单,因此运算速度较快。 32 | 33 | **缺点:**效果不好,放大图像时会出现严重的马赛克,缩小图像则会严重失真。它仅使用离待测采样点最近的像素的灰度值作为该采样点的灰度值,而没考虑其他相邻像素点的影响,因而重新采样后灰度值有明显的不连续性,图像质量损失较大,会产生明显的马赛克和锯齿现象。 34 | 35 | ### 2、双线性插值(Bilinear算法) 36 | 37 | 双线性插值即在两个方向分别进行一次线性插值,通过四个相邻像素插值得到待求像素。 38 | 39 | **优点:**最常见,最通用的算法之一,效果比最近邻插值法好。计算量较小,运算速度较快。图像连续性较好。双线性插值法效果要好于最近邻插值,只是计算量稍大一些,算法复杂些,程序运行时间也稍长些,但缩放后图像质量高,基本克服了最近邻插值灰度值不连续的特点,因为它考虑了待测采样点周围四个直接邻点对该采样点的相关性影响。 40 | 41 | **缺点:**放大时图像较为模糊,细节损失较严重。它仅考虑待测样点周围四个直接邻点灰度值的影响, 而未考虑到各邻点间灰度值变化率的影响, 因此具有低通滤波器的性质, 从而导致缩放后图像的高频分量受到损失, 图像边缘在一定程度上变得较为模糊。用此方法缩放后的输出图像与输入图像相比, 存在由于插值函数设计考虑不周而产生的图像质量受损与计算精度不高的问题。 42 | 43 | ### 3、双三次插值(Bicubic算法) 44 | 45 | 双三次插值是二维空间中最常用的插值方法。在这种方法中,函数f在点 (x,y) 的值可以通过矩形网格中最近的十六个采样点的加权平均得到,在这里需要使用两个多项式插值三次函数,每个方向使用一个。 46 | 47 | **优点:**立方卷积插值计算量最大,算法也是最为复杂的。在几何运算中,双线性内插法的平滑作用可能会使图像的细节产生退化,在进行放大处理时,这种影响更为明显。在其他应用中,双线性插值的斜率不连续性会产生不希望的结果。立方卷积插值不仅考虑到周围四个直接相邻像素点灰度值的影响,还考虑到它们灰度值变化率的影响。因此克服了最近邻算法和双线性算法的不足之处,能够产生比双线性插值更为平滑的边缘,计算精度很高,处理后的图像像质损失最少,效果是最佳的。 48 | 49 | **缺点:**立方卷积插值计算量较大,算法相较双线性算法更为复杂。 50 | 51 | ### 4、Lanczos算法 52 | 53 | 类似于双三次插值,对4x4的像素卷积处理,得到待求像素。 54 | 55 | **优点:**得到的图像在抗锯齿和保留锐利边缘的效果较好。 56 | 57 | **缺点:**相当于立方卷积插值,计算量较大,算法相较双线性算法更为复杂。 58 | 59 | 另外还有NEDI算法、EP2X算法、HQX算法、Google SR算法等。 60 | 61 | 参考: 62 | 63 | https://blog.csdn.net/allen_sdz/article/details/89166363 64 | 65 | 66 | 67 | ## 3. 图像特征提取算子 68 | 69 | 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子。它通过计算和统计图像局部区域的梯度方向直方图来构成特征。Hog特征结合SVM分类器已经被广泛应用于图像识别中,尤其在行人检测中获得了极大的成功。 70 | 71 | 参考: 72 | 73 | https://blog.csdn.net/a133521741/article/details/79237776 74 | 75 | 76 | 77 | ## 4. 卷积的作用 78 | 79 | 卷积从图像上来讲就是:**空间上的“加权求和”** 80 | 81 | 对于一些时序问题的卷积可以看作:**时间上的“加权求和”** 82 | 83 | 至于为什么不用全连接,因为放置参数爆炸。 84 | 85 | 卷积问题考察的较多,参考: 86 | 87 | https://blog.csdn.net/qq_42219077/article/details/88043384 88 | 89 | https://blog.csdn.net/libing_zeng/article/details/78209297 90 | 91 | 92 | 93 | ## 5. L1和L2正则化 94 | 95 | **L1和L2是正则化项,又叫做罚项,是为了限制模型的参数,防止模型过拟合而加在损失函数后面的一项。** 96 | 97 | **L1是模型各个参数的绝对值之和。L2是模型各个参数的平方和的开方值。** 98 | 99 | L1会趋向于产生少量的特征,而其他的特征都是0. 100 | 101 | 因为最优的参数值很大概率出现在坐标轴上,这样就会导致某一维的权重为0 ,产生稀疏权重矩阵 102 | 103 | L2会选择更多的特征,这些特征都会接近于0。 104 | 105 | 最优的参数值很小概率出现在坐标轴上,因此每一维的参数都不会是0。当最小化||w||时,就会使每一项趋近于0 106 | 107 | 参考: 108 | 109 | https://www.cnblogs.com/lyr2015/p/8718104.html 110 | 111 | https://blog.csdn.net/red_stone1/article/details/80755144 112 | 113 | 114 | 115 | ## 6. 随机梯度下降的优化算法 116 | 117 | 参数的自适应学习率的方法。 118 | 119 | 参考: 120 | 121 | https://blog.csdn.net/qq_35860352/article/details/80772142 122 | 123 | https://blog.csdn.net/u013453936/article/details/79004264 124 | 125 | 126 | 127 | ## 7. 排序算法总结 128 | 129 | 快排的时间复杂度是$O(nlogn)$ 130 | 131 | 参考: 132 | 133 | https://blog.csdn.net/hellozhxy/article/details/79911867 134 | 135 | 136 | 137 | ## 8. C++ const和宏定义的区别 138 | 139 | ### 1、编译器处理方式 140 | 141 | define – 在预处理阶段进行替换 142 | const – 在编译时确定其值 143 | 144 | ### 2、类型检查 145 | define – 无类型,不进行类型安全检查,可能会产生意想不到的错误 146 | const – 有数据类型,编译时会进行类型检查 147 | 148 | ### 3、内存空间 149 | define – 不分配内存,给出的是立即数,有多少次使用就进行多少次替换,在内存中会有多个拷贝,消耗内存大 150 | const – 在静态存储区中分配空间,在程序运行过程中内存中只有一个拷贝 151 | 152 | ### 4、其他 153 | 在编译时, 编译器通常不为const常量分配存储空间,而是将它们保存在符号表中,这使得它成为一个编译期间的常量,没有了存储与读内存的操作,使得它的效率也很高。 154 | 宏替换只作替换,不做计算,不做表达式求解。 155 | 156 | 参考: 157 | 158 | https://blog.csdn.net/yingyujianmo/article/details/51206460 159 | 160 | 161 | 162 | ## 9. 哈希表解决碰撞的几个方法 163 | 164 | 1、开放地址寻址法 165 | 166 | 2、再哈希法 167 | 168 | 3、链地址法(拉链法) 169 | 170 | 4、建立一个公共溢出区 171 | 172 | 参考: 173 | 174 | https://blog.csdn.net/hotchange/article/details/80159671 175 | 176 | https://blog.csdn.net/fhb1922702569/article/details/77506227 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /面试问题及答案汇总/网易严选—优化工程师-2面.md: -------------------------------------------------------------------------------- 1 | # 网易严选—优化工程师-2面 2 | 3 | ## 0x1 说一下研究生阶段最好的一个项目。 4 | 5 | 详细的解释了一下项目,因为项目里用到了CNN,然后面试官详细的问了一下为什么要用CNN,如何考量的。 6 | 7 | 然后也是比较详细的问了一下CNN里面所使用的损失函数,需要数学上的介绍和理解,以及优化的函数选择的是什么,有什么优势等。 8 | 9 | 我们项目里面使用的是**交叉熵**。给定两个概率分布p和q,通过q来表示p的交叉熵为: 10 | 11 | $H(p,q) = -\sum_{x}p(x)logq(x)$,其中,p(x)为真实的概率分布,q(x)为预测的概率分布。 12 | 13 | 参考:https://blog.csdn.net/weixin_37567451/article/details/80895309 14 | 15 | 优化函数选取的是 Adam。优势是速度快,可用于非平稳的目标或函数... 16 | 17 | 参考:https://www.jianshu.com/p/bd0c9e30a598 18 | 19 | 20 | 21 | ## 0x2 说一下研究生阶段最能展示你学习能力的一件事。 22 | 23 | Emmm,这个问题考察的就是如何吹牛批的能力吧。思考了10秒钟,然后开始和他瞎扯... 24 | 25 | 26 | 27 | ## 小总结 28 | 29 | 面试大概进行了25分钟。刚过笔试然后这个就叫2面了... 30 | 31 | 项目问了大概20分钟,主要了解了为什么要这么做,以及CNN相关的东西 32 | 33 | 第二个问题不太明白为何面试官都喜欢这么问,可能觉得,你自己要觉得自己都不能干啥,那还能干啥。。。 -------------------------------------------------------------------------------- /面试问题及答案汇总/腾讯-后台开发_1面.md: -------------------------------------------------------------------------------- 1 | # 腾讯-后台开发_1面 2 | 3 | ## 0x1 python2和python3的区别 4 | 5 | 1. 编码问题。`pyhon2`是`ASCII`编码(这是是`python2`经常出现问题的原因之一),`python3`改为了`Unicode`编码。所以在`python3`最开始不用加入`#coding: utf-8` 6 | 7 | 2. 整除。`python2`除法会直接取整,`python3`整除是浮点数。 8 | 9 | ```python 10 | # python2整除; 11 | >>> 1/2 12 | 0 13 | >>> 1.0/2.0 14 | 0.5 15 | 16 | # python3整除; 17 | >>> 1/2 18 | 0.5 19 | ``` 20 | 21 | 3. 语句变函数,如`exec`,`print`。`python2`的`print`是一个**语法结构**,`python3`的`print`是个**函数**。 22 | 23 | 4. `input`的问题。`python2`不能接受非字符串的输入,`python3`的`input`会将用户所有的输入都当作字符串对待。 24 | 25 | 5. 迭代器。`python2`的`xrange`相当于`python3`中的`range`。 26 | 27 | 6. `Nonlocal关键字`。python3加入了`nonlocal`关键字,可以在嵌套函数外访问嵌套函数里的变量。 28 | 29 | 7. Await async(异步IO) 30 | 31 | 参考:https://www.cnblogs.com/feifeifeisir/p/9599218.html 32 | 33 | 34 | 35 | ## 0x2 浅拷贝和深拷贝的区别 36 | 37 | **浅拷贝只是复制了对象的引用地址**,两个对象指向同一个内存地址,所以修改其中任意的值,另一个都会**随之改变**; 38 | 39 | **深拷贝是将对象及值复制过来**,两个对象修改其中任意的值另外一个值**不会变化**。 40 | 41 | ```python 42 | In [1]: import copy 43 | 44 | In [2]: atuple=(1,2,3,[4,5]) 45 | 46 | In [3]: b = copy.copy(atuple) # 浅拷贝,b和atuple其实是同一个,一个改变另外一个跟着改变 47 | 48 | In [4]: c = copy.deepcopy(atuple) # 深拷贝,c和atuple不一样,一个改变另外一个不改变 49 | 50 | In [5]: print(atuple, b, c) 51 | (1, 2, 3, [4, 5]) (1, 2, 3, [4, 5]) (1, 2, 3, [4, 5]) 52 | 53 | In [6]: atuple[3].append(6) 54 | 55 | In [7]: print(atuple, b, c) 56 | (1, 2, 3, [4, 5, 6]) (1, 2, 3, [4, 5, 6]) (1, 2, 3, [4, 5]) 57 | 58 | In [8]: c[3].append(10) 59 | 60 | In [9]: print(atuple, b, c) 61 | (1, 2, 3, [4, 5, 6]) (1, 2, 3, [4, 5, 6]) (1, 2, 3, [4, 5, 10]) 62 | ``` 63 | 64 | 65 | 66 | ## 0x3 多线程和多进程的区别,应该如何选择使用? 67 | 68 | 大量需要CPU计算,需要稳定性的时候,选择进程(比如web程序); 69 | 70 | 大量切换CPU的时候,与用户IO交互多的,选择线程(比如,图像处理,算法处理); 71 | 72 | | **对比维度** | **多进程** | **多线程** | **总结** | 73 | | -------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | 74 | | 数据共享、同步 | 数据共享复杂,需要用IPC;数据是分开的,同步简单 | 因为共享进程数据,数据共享简单,但也是因为这个原因导致同步复杂 | 各有优势 | 75 | | 内存、CPU | 占用内存多,切换复杂,CPU利用率低 | 占用内存少,切换简单,CPU利用率高 | 线程占优 | 76 | | 创建销毁、切换 | 创建销毁、切换复杂,速度慢 | 创建销毁、切换简单,速度很快 | 线程占优 | 77 | | 编程、调试 | 编程简单,调试简单 | 编程复杂,调试复杂 | 进程占优 | 78 | | 可靠性 | 进程间不会互相影响 | 一个线程挂掉将导致整个进程挂掉 | 进程占优 | 79 | | 分布式 | 适应于多核、多机分布式;如果一台机器不够,扩展到多台机器比较简单 | 适应于多核分布式 | 进程占优 | 80 | 81 | 参考:https://www.cnblogs.com/virusolf/p/5458325.html 82 | 83 | 84 | 85 | ## 0x4 进程通信的方式 86 | 87 | 有5种方式: 88 | 89 | 1.管道:速度慢,容量有限,只有父子进程能通讯 90 | 91 | 2.FIFO(命名管道):任何进程间都能通讯,但速度慢 92 | 93 | 3.消息队列:容量受到系统限制,且要注意第一次读的时候,要考虑上一次没有读完数据的问题 94 | 95 | 4.信号量:不能传递复杂消息,只能用来同步 96 | 97 | 5.共享内存区:能够很容易控制容量,速度快,但要保持同步,比如一个进程在写的时候,另一个进程要注意读写的问题,相当于线程中的线程安全,当然,共享内存区同样可以用作线程间通讯,不过没这个必要,线程间本来就已经共享了同一进程内的一块内存 98 | 99 | 6.套接字(socket): 100 | 101 | 参考1:https://www.cnblogs.com/zgq0/p/8780893.html 102 | 103 | 参考2:https://blog.csdn.net/wm12345645/article/details/82381407 104 | 105 | python提供了多种进程通信的方式,主要Queue和Pipe这两种方式,Queue用于多个进程间实现通信,Pipe是两个进程的通信 106 | 107 | 参考:https://www.cnblogs.com/guguobao/p/9398653.html 108 | 109 | 110 | 111 | ## 0x5 TCP和UDP的区别 112 | 113 | - TCP 是面向连接的,UDP 是面向无连接的 114 | - UDP程序结构较简单 115 | - TCP 是面向字节流的,UDP 是基于数据报的 116 | - TCP 保证数据正确性,UDP 可能丢包 117 | - TCP 保证数据顺序,UDP 不保证 118 | 119 | 参考:https://blog.csdn.net/zhang6223284/article/details/81414149 120 | 121 | 122 | 123 | ## 0x6 决策树有那几种类型 124 | 125 | ID3、C4.5、CART等三种。 126 | 127 | **ID3算法**的核心是在决策树各个子节点上应用信息增益准则选择特征,递归的构建决策树,具体方法是:从根节点开始,对节点计算所有可能的特征的信息增益,选择信息增益最大的特征作为节点的特征,由该特征的不同取值建立子节点;再对子节点递归调用以上方法,构建决策树。直到所有特征的信息增益均很小或没有特征可以选择为止。最后得到一个决策树。 128 | 129 | 缺点在于:**用信息增益选择属性时偏向于选择分枝比较多的属性值,即取值多的属性**。**不能处理连续属性。** 130 | 131 | **C4.5是对ID3的改进**。主要有以下改进: 132 | 133 | > 用信息增益来选择属性; 134 | > 135 | > 在决策树的构造过程中对树进行剪枝; 136 | > 137 | > 对非离散数据也能处理; 138 | > 139 | > 能够对不完整数据进行处理; 140 | 141 | **CART算法**选择分裂属性的方式是比较有意思的,首先计算不纯度,然后利用不纯度计算Gini指标。以满意度预警模型为例,计算自变量故障原因的Gini指标时,先按照故障原因可能的子集进行划分 142 | 143 | 参考1:https://blog.csdn.net/LA401088242/article/details/89034077 144 | 145 | 参考2:https://blog.csdn.net/gumpeng/article/details/51397737 146 | 147 | 148 | 149 | ## 0x7 Mysql索引结构 150 | 151 | Mysql索引一般可以有:BTree索引,哈希索引,全文索引等;一般采取B+树作为索引。 152 | 153 | > **B+树磁盘读写代价更低**:因为B+树的所有**非叶子节点只会存放索引信息**,而**真正的数据信息都只存放在叶子节点**中,这样一来,每个非叶子节点存放的索引信息就更多,一次磁盘IO就可以读取更多的索引信息到内存中,可以减少磁盘IO的次数。 154 | > 155 | > **B+树查询效率更加稳定**:由于非叶子节点只存索引信息,而没有真正的数据信息,所以任何关键字的查找必须走一条从根结点到叶子结点的路。所有关键字查询的路径长度相同,导致每一个数据的查询效率相当。 156 | > 157 | > **B+树更加适合在区间查询的情况**:由于B+树的数据都存储在叶子结点中,非叶子结点均为索引,只需要扫一遍叶子结点即可得到所有数据信息,但是B树因为其非叶子结点同样存储着数据,我们要找到具体的数据,需要进行一次中序遍历按序来扫,所以B+树更加适合在区间查询的情况,所以通常B+树用于数据库索引。 158 | 159 | 参考1:https://my.oschina.net/edwardge/blog/1934165 160 | 161 | 参考2:https://blog.csdn.net/caohao0591/article/details/80962308 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /面试问题及答案汇总/腾讯-后台开发_2面.md: -------------------------------------------------------------------------------- 1 | # 腾讯-后台开发-2面 2 | 3 | ## 0x1 说一下做的最好的一个项目,解决的最大的痛点在哪 4 | 5 | 巴拉巴拉 6 | 7 | 8 | 9 | ## 0x2 说一下LINUX下面查看进程端口、IO和端口占用的命令 10 | 11 | ``` 12 | ps -aux | grep [name] 13 | netstat -nap | grep [pid] 14 | Iotop 15 | ``` 16 | 17 | 18 | 19 | ## 0x3 说一下mysql和ES的区别 20 | 21 | 巴拉巴拉 22 | 23 | ## 0x4 让说一个mysql查询语句 24 | 25 | 一张表,存储的是一个班级所有的同学以及4门科目对应的成绩,比如(张三,90,80,70,95) 26 | 27 | 问你如何找出每个同学的最高分数以及对应的科目... 28 | 29 | 30 | 31 | ## 0x5 如何看linux下进程占用的内存,python里面如何查看一个字典所占用的内存 32 | 33 | ## 0x6 说一下你理解的spark 34 | 35 | ## 0x7 家在哪,以后想去哪工作 36 | 37 | -------------------------------------------------------------------------------- /面试问题及答案汇总/腾讯-后台开发_3面.md: -------------------------------------------------------------------------------- 1 | # 腾讯-后台开发_3面 2 | 3 | ## 0x1 说一下项目 4 | 5 | 巴拉巴拉 6 | 7 | ## 0x2 Python同步和异步的区别? 8 | 9 | 同步:多任务, 多个任务之间执行的时候要求有**先后顺序**,必须**一个先执行完成之后,另一个才能继续执行**, 只有一个主线 10 | 11 | 异步:多任务, 多个任务之间执行**没有先后顺序**,可以同时运行,执行的先后顺序不会有什么影响,存在的多条运行主线 12 | 13 | 阻塞:从调用者的角度出发,如果在调用的时候,**被卡住,不能再继续向下运行,需要等待,就说是阻塞** 14 | 15 | 非阻塞: 从调用者的角度出发, 如果在调用的时候,**没有被卡住,能够继续向下运行,无需等待,就说是非阻塞** 16 | 17 | 参考1:https://www.jianshu.com/p/6c1d04f7b3f7s 18 | 19 | 参考2:https://blog.csdn.net/fanzhanxin/article/details/86657291 20 | 21 | ## 0x3 Python相比C\C++的优缺点在哪里? 22 | 23 | 优点如下: 24 | 25 | 1. 简单易学,上手快。 26 | 2. 开发效率高,有很多功能强大的第三方库 27 | 3. 高级语言,无需考虑底层实现细节 28 | 4. 可移植性强,基本可以在所有平台上运行 29 | 5. 可扩展性 30 | 6. 可嵌入性,可嵌入到C/C++程序中 31 | 32 | 缺点如下: 33 | 34 | 1. 速度慢,因为是解释性语言,所以效率比较低 35 | 2. 代码不能加密 36 | 3. 线程不能利用多CPU的问题。也就是并不是真正的多线程,有GIL全局锁,任一时刻只有一个线程在运行。 37 | 38 | 参考:https://www.cnblogs.com/wangkun122/p/9078777.html 39 | 40 | ## 0x4 逻辑回归和线性回归的区别 41 | 42 | ​ 1)线性回归要求因变量**服从正态分布**,logistic回归对变量分布没有要求。 43 | 44 |  2)线性回归要求因变量(Y)是**连续性数值变量**,而logistic回归要求因变量是分类型变量。 45 | 46 |  3)线性回归要求**自变量和因变量呈线性关系**,而logistic回归不要求自变量和因变量呈线性关系 47 | 48 |  4)线性回归是**直接分析因变量与自变量的关系**,而logistic回归是**分析因变量取某个值的概率与自变量的关系** 49 | 50 | 参考:https://www.cnblogs.com/always-fight/p/10729982.html 51 | 52 | ## 0x5 三次握手如果只握两次会发生什么? 53 | 54 | 两次握手的话,只有客户端已经建立好连接了,而此时服务器端是没有建立好连接的。 55 | 56 | 如果只握两次,则服务器端会一直处于等待的状态。。 57 | 58 | 参考:https://blog.csdn.net/ljq140421/article/details/77864208 59 | 60 | ## 0x6 职业规划,以后想从事的岗位以及需要具备哪些能力。问了两遍。 61 | 62 | 自己的兴趣 + 自己的能力 + 公司所能给的支持 + 岗位的认知 63 | 64 | 主要从自己喜欢什么?自己能做什么?公司需要什么样的人?这几个方面做回答。 65 | 66 | 既需要对自己有一个清晰的认知,也需要对发展前景以及公司的岗位比较清楚。 67 | 68 | 参考:https://www.shixiseng.com/cheerstation/csa_h8dzswaeeyuo -------------------------------------------------------------------------------- /面试问题及答案汇总/艾耕科技1面.md: -------------------------------------------------------------------------------- 1 | # 艾耕科技1面 2 | 3 | 已凉。问了全技术栈的所有问题。 4 | 5 | -------------------------------------------------------------------------------- /面试问题及答案汇总/追一科技-算法工程师_1面.md: -------------------------------------------------------------------------------- 1 | # 追一科技-算法工程师_1面 2 | 3 | 时间:2019年8月21日 14:00-15:00 4 | 5 | 感受:问的问题很细致,对原理要求比较高。我对原理性的知识了解的不多,所以回答的不好。需要做专题来复习。 6 | 7 | ## 0x1 项目介绍 8 | 9 | 介绍完项目之后,问了项目里面参数的详细设置,以及数据集的收集和处理的流程。紧接着问了: 10 | 11 | 1. 决策树的构造过程,以及如何防止过拟合,如何减枝? 12 | 2. SVM函数优化的是什么东西,有哪些限制条件?其实就是问了SVM的公式等问题。 13 | 3. 二分类的评价指标有哪些,AUC曲线的含义是什么,AUC值为0.5和0.4哪个更好? 14 | 15 | ## 0x2 CNN问题 16 | 17 | 在这一块主要考察了一些简单的CNN操作,问了: 18 | 19 | 1. 卷积运算的时间复杂度是多少?说出推导的过程。 20 | 21 | 在这里详细说了一下卷积的过程,然后卷积后卷积层的大小,最后是需要计算这个卷积的过程中有多少个加法操作和乘法操作。 22 | 23 | 2. 两个3\*3的卷积核1个5\*5的卷积哪个更好,为什么? 24 | 25 | 首先两者都具有同样大小的输出和感受野。如果图像大小为n的话,两者的输出都是n-4。 26 | 27 | 1)网络层数增加了,也就增加非线性表达的能力。 28 | 29 | 2)参数变少了,两个3\*3的参数为18,而1个5\*5的参数为25。 30 | 31 | 32 | 33 | ## 0x3 K近邻问题 34 | 35 | 技术栈里面写到了K近邻,问了: 36 | 37 | 1. K近邻是什么含义,如何判断一个点的标签? 38 | 39 | 2. 假设如果我们使用距离运算的方法得到了与所有点与该点的距离,得到了一个数组,如何找到其最小的K个值?假设数组为arr. 40 | 41 | 我:如果是Python里面,直接使用sort函数进行排序即可得到。 42 | 43 | 面试官:这样的复杂度是多少? 44 | 45 | 我:调用的库的复杂度应该是最小的,那么应该为$Nlog(N)$ 46 | 47 | 面试官:是的。现在得到的baseline就是$Nlog(N)$,有更快的方法吗? 48 | 49 | 我:创建一个空间为K的数组res,然后存放arr的前K个元素,并排序。然后遍历arr,不断更新res。 50 | 51 | 面试官:这样的复杂度是多少呢? 52 | 53 | 我:...来来回回计算了几遍之后,得到复杂度为:$Klog(K) + Nlog(K)$,是比直接调用sort更快的。 54 | 55 | 56 | 57 | ## 0x4 损失函数问题 58 | 59 | 技术栈里写了会基本的机器学习算法,然后问了: 60 | 61 | 1. 说一下线性回归的损失函数。为什么要选这个,这个损失函数的假设是什么? 62 | 63 | 我回答了均方误差。然后就是上述的问题,不了解假设情况。 64 | 65 | 结束后问面试官,这种问题如何考虑。面试官回答,我们选择损失函数,都是有假设条件的,所以主要看这个假设条件对应的分布是什么,其实本质上是选择噪音的分布,是高斯分布,泊松分布还是其它的分布。 66 | 67 | 68 | 69 | ...期间还穿插了很多小的简单的问题,记不太清了。 70 | 71 | ## 0x5 一个算法问题 72 | 73 | 题目描述:给定一个排好序的数组,给定一个target。如果target在数组里,返回target**第一次**出现的位置,如果不存在,返回-1。 74 | 75 | 在这里对话也是面试官引导给出正确的解答的过程。我最初提出二分法,然后面试官不断询问更快的方法。 76 | 77 | ​ 我:用二分法来做 78 | 79 | ​ 面试官:二分法的步骤详细说下一下 80 | 81 | ​ 我:选定begin, end,然后计算出mid。这里最重要的问题是什么时候跳出循环,直接给出最后的解答供思考和理解。 82 | 83 | 1. 如**果mid对应的值等于target,mid-1对应的值小于target**,则找到了第一次出现的位置,退出; 84 | 2. 如果mid对应和mid-1的值均大于等于target,则end的值为mid - 1; 85 | 3. 如果mid和mid-1的值均小于target,则begin的值设置为mid+1 86 | 87 | 最后问,这样做的时间复杂度是多少。这样做其实就是一个标准的二分法,复杂度应该为:log(N) 88 | 89 | 90 | 91 | Mark: 面试官说,**二分法的本质思想是通过一个条件排除掉一半的可能性**。其实自己平时在用这些算法的时候,根本就没有深刻的理解算法的含义,所以其实理解了这句话,就理解了二分法如何快速的解决问题了。然后得想清楚使用二分法的时候,什么时候跳出循环。 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /面试问题及答案汇总/阿里云CDN-机器学习算法.md: -------------------------------------------------------------------------------- 1 | # 阿里云CDN-机器学习算法 2 | 3 | ## 0x1 项目问题 4 | 5 | 主要问了恶意代码同源分析如何实现,比如灰度图这块,是如何来解释的,比如一个删除文件的操作是如何在图片上显示的,考察的较多的是算法的可解释性。 6 | 7 | 然后对于毕设项目来说主要的问题在于机器学习里面随机森林的效果较好主要原因是有些特征的性质比较好,然后是数据的原因,并不是算法的优势。 8 | 9 | 10 | 11 | ## 0x2 算法问题 12 | 13 | 给一个500G的文本,里面全是URL,给2G的内存,无限硬盘,如何快速找到Top 100的URL? 14 | 15 | 参考1: http://blog.sina.com.cn/s/blog_a0db4ee90102vrzk.html 16 | 17 | 参考2: https://blog.csdn.net/tiankong_/article/details/77239501 18 | 19 | 参考3: https://blog.csdn.net/kingyuan666/article/details/84584017 20 | 21 | 参考4: https://blog.csdn.net/kingyuan666/article/details/84501930 22 | 23 | 24 | ## 0x3 进程和线程的区别 25 | 26 | 根本区别:**进程是操作系统资源分配的基本单位,而线程是任务调度和执行的基本单位** 27 | 28 | 在开销方面:每个进程都有独立的代码和数据空间(程序上下文),程序之间的切换会有较大的开销;线程可以看做轻量级的进程,同一类线程共享代码和数据空间,每个线程都有自己独立的运行栈和程序计数器(PC),线程之间切换的开销小。 29 | 30 | 所处环境:在操作系统中能同时运行多个进程(程序);而在同一个进程(程序)中有多个线程同时执行(通过CPU调度,在每个时间片中只有一个线程执行) 31 | 32 | 内存分配方面:系统在运行的时候会为每个进程分配不同的内存空间;而对线程而言,除了CPU外,系统不会为线程分配内存(线程所使用的资源来自其所属进程的资源),线程组之间只能共享资源。 33 | 34 | 包含关系:没有线程的进程可以看做是单线程的,如果一个进程内有多个线程,则执行过程不是一条线的,而是多条线(线程)共同完成的;线程是进程的一部分,所以线程也被称为轻权进程或者轻量级进程。 35 | 36 | 37 | 38 | 参考:https://blog.csdn.net/kuangsonghan/article/details/80674777 39 | 40 | ## 0x4 三次握手&四次握手 41 | 42 | ![img](https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2590032753,2466318043&fm=173&app=49&f=JPEG?w=640&h=716&s=E7F239D247AFCCEA106594580300D072) 43 | 44 | **三次握手建立连接:** 45 | 46 | **第一次握手:**客户端发送syn包(seq=x)到服务器,并进入SYN_SEND状态,等待服务器确认;**第二次握手:**服务器收到syn包,必须确认客户的SYN(ack=x+1),同时自己也发送一个SYN包(seq=y),即SYN+ACK包,此时服务器进入SYN_RECV状态;**第三次握手:**客户端收到服务器的SYN+ACK包,向服务器发送确认包ACK(ack=y+1),此包发送完毕,客户端和服务器进入ESTABLISHED状态,完成三次握手。 47 | 48 | **四次握手断开连接:** 49 | 50 | **第一次挥手:**主动关闭方发送一个FIN,用来关闭主动方到被动关闭方的数据传送,也就是主动关闭方告诉被动关闭方:我已经不会再给你发数据了(当 然,在fin包之前发送出去的数据,如果没有收到对应的ack确认报文,主动关闭方依然会重发这些数据),但此时主动关闭方还可以接受数据。 51 | 52 | **第二次挥手:**被动关闭方收到FIN包后,发送一个ACK给对方,确认序号为收到序号+1(与SYN相同,一个FIN占用一个序号)。 53 | 54 | **第三次挥手:**被动关闭方发送一个FIN,用来关闭被动关闭方到主动关闭方的数据传送,也就是告诉主动关闭方,我的数据也发送完了,不会再给你发数据了。 55 | 56 | **第四次挥手:**主动关闭方收到FIN后,发送一个ACK给被动关闭方,确认序号为收到序号+1,至此,完成四次挥手。 57 | 58 | 参考1:https://blog.csdn.net/qq_35860138/article/details/82054793 59 | 60 | 参考2 : https://baijiahao.baidu.com/s?id=1618114723935605183&wfr=spider&for=pc 61 | 62 | 63 | 64 | ## 0x5 C语言二分法 65 | 66 | ### 1) 给定一个升序数组A和一个target,查找A中是否有target,有则返回索引值,无则返回-1. 67 | 68 | ```c 69 | #include 70 | int binarySearch(int A[], int target, int n) { 71 | int low, high, mid; 72 | mid = -1; 73 | low = 0; 74 | high = n - 1; 75 | while (low <= high) { /* 这里比较重要的一点就是必须要等于,因为有可能就是其中一个数 */ 76 | mid = low + high; 77 | mid /= 2; 78 | if (target < A[mid]) 79 | high = mid - 1; 80 | else if (target > A[mid]) 81 | low = mid + 1; 82 | else 83 | break; 84 | } 85 | if (mid == -1) 86 | return 0; 87 | else 88 | return mid; 89 | } 90 | 91 | int main() { 92 | int A[] = {1, 2, 3, 5 ,10}; 93 | int c = binarySearch(A, 2, 5); 94 | } 95 | ``` 96 | 97 | ### 2) 打印一个未知长度的链表的索引中间的数值,如果为偶数则打印两个,奇数则打印一个 98 | 99 | ```c 100 | # include 101 | # include 102 | 103 | struct NODE 104 | { 105 | int data; 106 | struct NODE* next; 107 | }; 108 | 109 | /* Function to get the middle of the linked list*/ 110 | void print_middle_element(struct NODE *head) 111 | { 112 | struct NODE *p1, *p2; 113 | p1->next = head; 114 | p2 = head; 115 | int tag; 116 | tag = 0; 117 | 118 | if (head == NULL) { 119 | printf("没有中间节点"); 120 | } 121 | 122 | while(p2->next != NULL) { 123 | if (p2->next->next != NULL) { /* 偶数的情况 */ 124 | p2 = p2->next->next; 125 | p1 = p1->next; 126 | } 127 | else { /* 奇数的情况 */ 128 | p2 = p2->next; 129 | p1 = p1->next; 130 | tag = 1; 131 | } 132 | } 133 | if (tag == 0) { /* 最中间的两个元素mid1和mid2 */ 134 | int mid1 = p1->data; 135 | int mid2 = p1->next->data; 136 | printf("mid1 = %d", mid1); 137 | printf("mid2 = %d", mid2); 138 | } 139 | else { /* 最中间的一个元素mid */ 140 | int mid = p1->next->data; 141 | printf("mid = %d", mid); 142 | } 143 | } 144 | ``` 145 | 146 | 147 | 148 | --------------------------------------------------------------------------------