ccf202006-1线性分类器


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int point_count = scanner.nextInt();
        int line_count = scanner.nextInt();
        scanner.nextLine();
        Map<String, List<Point>> pointMap = new HashMap<>();
        for(int i = 0; i < point_count; i++){
            String line = scanner.nextLine();
            String[] arr = line.split(" ");
            String categoryName = arr[2];
            Point point = new Point(Double.valueOf(arr[0]), Double.valueOf(arr[1]));
            if(pointMap.containsKey(categoryName)){
                List<Point> pointList = pointMap.get(categoryName);
                pointList.add(point);
            }
            else{
                List<Point> pointList = new ArrayList<>();
                pointList.add(point);
                pointMap.put(categoryName,pointList);
            }
        }

        for(int i = 0; i < line_count; i++){
            double theta0 = scanner.nextDouble();
            double theta1 = scanner.nextDouble();
            double theta2 = scanner.nextDouble();
            for(Map.Entry<String, List<Point>> entry : pointMap.entrySet()){
                for(Point point : entry.getValue()){
                    double result = theta0 + theta1 * point.x + theta2 * point.y;
                    point.isPositive = result > 0 ? true : false;
                }
            }
            boolean bFind = false;
            for(Map.Entry<String, List<Point>> entry : pointMap.entrySet()){
                Point pointFirst = entry.getValue().get(0);
                for(Point point : entry.getValue()){
                    if(point.isPositive != pointFirst.isPositive){
                        System.out.println("No");
                        bFind = true;
                        break;
                    }
                }
                if(bFind){
                    break;
                }
            }
            if(!bFind){
                System.out.println("Yes");
            }
        }
    }
}


class Point {
    double x;
    double y;

    boolean isPositive = false;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
}

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值