CSP-Nov1-linear classifier
问题描述:
满分参考代码(python):
#encoding:utf-8
"""
reference:http://118.190.20.162/view.page?gpid=T105
Author:Hanger
"""
def judge(points,k0,k1,k2): #保证点不在直线上
result1 = []
result2 = []
for i in range(len(points)):
if k0+k1*points[i][0]+k2*points[i][1] > 0:
result1.append(points[i][2])
elif k0+k1*points[i][0]+k2*points[i][1] < 0:
result2.append(points[i][2])
if (points[i][2] in result1 ) and (points[i][2] in result2):
return False
#判断result1和result2中的类别是否都相同
if len(set(result1))==1 and len(set(result2))==1:
return True
else:
return False
n,m = list(map(int,input().split()))
points = []
for i in range(n):
points.append(list(input().split()))
#把前两位字符串转化为int
for i in range(n):
points[i][0] = int(points[i][0])
points[i][1] = int(points[i][1])
for i in range(m):
k0,k1,k2 = list(map(int,input().split()))
if judge(points,k0,k1,k2):
print("Yes")
elif not judge(points,k0,k1,k2):
print("No")