202006-1 线性分类器
1. 题目介绍
2. Python代码
n,m = map(int,input().split())
point = [0]*n
judgments = []
for i in range(n):
point[i] = list(input().split())
point[i][:2] = map(int,point[i][:2])
for j in range(m):
inquire = list(map(int,input().split()))
type_1 = []
type_2 = []
for i in range(n):
if inquire[2] != 0:
y = (inquire[0]+inquire[1]*point[i][0])/(-inquire[2])
if point[i][1]>y :
type_1.extend(point[i][2])
else:
type_2.extend(point[i][2])
else:
x = (inquire[0]+inquire[2]*point[i][1])/(-inquire[1])
if point[i][0]>x :
type_1.extend(point[i][2])
else:
type_2.extend(point[i][2])
if ('A' not in type_1 and 'B' not in type_2) or ('B' not in type_1 and 'A' not in type_2):
judgments.extend(['Yes'])
else:
judgments.extend(['No'])
for judgment in judgments:
print(judgment)
3.测试结果:
- 总结:小白刚刚接触csp,若代码算法关于简单,过于暴力望谅解