202006-1线性分类器

线性分类器

package practice;

import java.util.Scanner;

import javax.swing.text.StyledEditorKit.ForegroundAction;

public class pc {
 public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();//点的个数
    int m = sc.nextInt();//线的个数
    int a = 0;//A点的个数
    int b = 0;//B点的个数
    int ra = 0;//在线的一边的a点的个数
    int rb = 0;//在线的一边的b点的个数
    int[] Ax = new int[n];
    int[] Ay = new int[n];
    int[] Bx = new int[n];
    int[] By = new int[n];
    String[] result =new String[m];//存储对应线是否为指定的线
    for(int i = 0;i<n;i++) {
    	int x = sc.nextInt();//获取点的x坐标
    	int y = sc.nextInt();//获取点的y坐标
    	char ch = sc.next().charAt(0);//获取指定的A或者B点
    	if (ch == 'A') {
    		Ax[a] = x;
    		Ay[a] = y;
    		a++;
		}else if (ch == 'B') {
			Bx[b] = x;
			By[b] = y;
			b++;
		}
    }
   for (int i = 0; i < m; i++) {//获取线进行判断
	int a0 = sc.nextInt();
	int a1 = sc.nextInt();
	int a2 = sc.nextInt();
	for (int t = 0; t < a; t++) {//依次带入A点
		int at = a0+a1*Ax[t]+a2*Ay[t];
		if (at>0) {
			ra++;
		}
	}
	for (int q = 0; q < b; q++) {//依次带入B点
		int bt = a0+a1*Bx[q]+a2*By[q];
		if (bt>0) {
			rb++;
		}
	}
	if ((ra==a&&rb==0)||(ra==0&&rb==b)) {
		result[i] = "Yes";
	}else {
		result[i] = "No";
	}
	ra=0;
	rb=0;
}
   for (int i = 0; i < result.length; i++) {
	System.out.print(result[i]+"\n");
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值