• CCF-202006-1线性分类器


     
    1
    def judga(lis1,z): #判断列表lis1中点是否都在线z的一侧 2 s=0 3 for i in lis1: 4 if z[0]+i[0]*z[1]+i[1]*z[2]>0: 5 s+=1 6 if s==len(lis1) or s==0: 7 return True 8 else: 9 return False 10 11 12 13 def judg(x,y,z):#判断A类点x,B类点y是否在线Z不同侧 14 flag = False 15 if (z[0]+x[0]*z[1]+x[1]*z[2])*(z[0]+y[0]*z[1]+y[1]*z[2])<0: 16 flag = True 17 return flag 18 19 20 21 if __name__ == '__main__': 22 da_list = [] 23 db_list = [] 24 d_list = [] 25 n, m = map(int,input().split()) 26 for i in range(n):#点的输入 27 raw = input() 28 x, y, z = raw.split() 29 x = int(x) #由于raw输入将看作字符串输入,所以要整形化 30 y = int(y) 31 tub1 = (x,y,z) 32 if tub1[2]=='A': 33 da_list.append(tub1) 34 else: 35 db_list.append(tub1) 36 for i in range(m): 37 a, b, c = map(int, input().split()) 38 tub2 = (a, b, c) 39 d_list.append(tub2) 40 for i in range(m): 41 if judga(da_list,d_list[i])==True and judga(db_list,d_list[i])==True: 42 if judg(da_list[0],db_list[0],d_list[i]): 43 print('Yes') 44 else: 45 print('No') 46 else: 47 print('No')
  • 相关阅读:
    MySQL5.7初始密码查看及重置
    ps top kill
    Linux基础知识[2]【延迟及定时机制】
    大数加减运算
    字符串分隔
    打印NxN的矩阵
    交叉排序
    去除重复字符并排序
    大数求差——(华为实习招聘机试题)
    图解TCP-IP协议
  • 原文地址:https://www.cnblogs.com/zero-16451/p/13508199.html
Copyright © 2020-2023  润新知