CSP 202006-1 线性分类器 python实现+详解

tech2022-07-30  136

试题

代码

# 读入m,n m, n = [int(i) for i in input().split()] # 创建字典存放已知点 dict = {} for i in range(m): line = input().split() x, y, t = line x, y = int(x), int(y) dict[(x, y)] = t # 逐条线地去判断每一个点 # 创建两个集合,一个存放坐标代入公式后大于零的点,另一个……小于…… # 如果线可以将A,B两类点分开,则每个集合只会存在A/B一种类型 for i in range(n): setSmall = set() setBig = set() line = input().split() a, b, c = [int(i) for i in line] for k, v in dict.items(): x, y = k[0], k[1] if a + b*x + c*y < 0: setSmall.add(v) else: setBig.add(v) if len(setSmall) == len(setBig) == 1: print('Yes') else: print('No')
最新回复(0)