版本比较
题解:P14708 [ICPC 2023 Tehran R] Micromasters Certificates
正文
增加 7 行删除 7 行
49 行未改动50515253545455565757585960616263646465666768686970717253 行未改动1261271281291301301311321331349 行未改动1441451461471481481491501511523 行未改动15615715815916016016116216316416549 行未改动 board = [line.rstrip('\n') for line in sys.stdin] if not board: print(0) return
rows = len(board) cols = len(board[0]) if rows > 0 else 0
# 步骤1:收集所有'+'的坐标 plus_coords = [] for i in range(rows): for j in range(len(board[i])): if board[i][j] == '+': plus_coords.append((i, j))
# 步骤2:识别所有矩形框(top, bottom, left, right) boxes = [] processed = set() # 避免重复识别框
for (i, j) in plus_coords: if (i, j) in processed: continue # 向右找同行的'+'(水平边)53 行未改动 for x in [top, bottom]: for y in [left, right]: processed.add((x, y)) boxes.append((top, bottom, left, right))
# 步骤3:提取每个框内的课程并标准化 course_sets = [] for (top, bottom, left, right) in boxes: courses = set()9 行未改动 if clean_content: # 非空才加入 courses.add(clean_content) if courses: # 确保框内有课程 course_sets.append(courses)
# 步骤4:枚举所有3个框的组合,计算最小并集大小 min_total = float('inf') # 枚举所有3个框的组合(最多C(50,3)=19600次,效率足够) for combo in combinations(course_sets, 3):3 行未改动 union.update(s) total = len(union) if total < min_total: min_total = total
print(min_total)
if __name__ == "__main__": main()```