滴滴笔试0917
刷栅栏写了一大堆只过了18%,哭死
写完都没时间做第一题了
import numpy as np if __name__ == '__main__': temp = input().split() n, p, q = int(temp[0]), int(temp[1]), int(temp[2]) records_shuaqi = []# 刷漆的记录数组 for i in range(3): temp = input().split() temp = [int(temp_i) for temp_i in temp] records_shuaqi.append(temp) records_shuaqi = np.array(records_shuaqi) records_shuaqi_reshape = [] col = records_shuaqi.shape[1] for i in range(col): arr = [records_shuaqi[0][i], records_shuaqi[1][i], records_shuaqi[2][i]] records_shuaqi_reshape.append(arr) painted = {}# 字典,用来记录每个栅栏被刷过的漆的类型和次数 for i in range(col): start, end, type = records_shuaqi_reshape[i][0], records_shuaqi_reshape[i][1], records_shuaqi_reshape[i][2] for j in range(start, end + 1):# start~end号栅栏 if str(j) not in painted: painted[str(j)] = {} if str(type) not in painted[str(j)]: painted[str(j)][str(type)] = 1 else: painted[str(j)][str(type)] += 1 count = 0 keys = [] for k in painted.keys(): keys.append(k) index = 0 for k, v in painted.values(): if int(k) == 1 and painted[keys[index]]['1'] >= p and int(v) == 2 and painted[keys[index]]['2'] >= q: count += 1 if int(k) == 2 and painted[keys[index]]['2'] >= q and int(v) == 1 and painted[keys[index]]['1'] >= p: count += 1 index += 1 print(count)