202006-1 线性分类器

202006-1 线性分类器

1. 题目介绍

2. Python代码

n,m = map(int,input().split()) # n为点的个数, m为查询的个数
point = [0]*n # 点信息集合二维数组
judgments = [] # 判断的结果
for i in range(n):
    point[i]  = list(input().split()) # 输入n个点的信息
    point[i][:2] = map(int,point[i][:2]) # 将坐标转换为整数

for j in range(m):
    inquire = list(map(int,input().split())) # 输入m个查询的信息,直线的三个参数
    type_1 = [] #分为两类
    type_2 = []
    for i in range(n):
        if inquire[2] != 0:
            y = (inquire[0]+inquire[1]*point[i][0])/(-inquire[2]) # 线上面对应X的y的值
            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,若代码算法关于简单,过于暴力望谅解
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿明同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值