-
问题链接:线性分类器
-
问题分析:模拟法解决。
-
程序说明:A、B数组分别存A、B类。
-
程序代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
int m = reader.nextInt();
int [][]A = new int[n][2];
int [][]B = new int[n][2];
int A1=0;int B1=0;
for(int i=0;i<n;i++) {
int x = reader.nextInt();
int y = reader.nextInt();
char t = reader.next().charAt(0);
if(t=='A') {
A[A1][0]=x;
A[A1][1]=y;
A1++;
}
else {
B[B1][0]=x;
B[B1][1]=y;
B1++;
}
}
int z1=0,z2=0,z3=0;
String []res = new String[m];
//>0 true <0 false
for(int i=0;i<m;i++) {
Boolean flagA = true;
Boolean flagA2 = true;
Boolean flagB = true;
Boolean flagB2 = true;
Boolean flag = true;
z1=reader.nextInt();
z2=reader.nextInt();
z3=reader.nextInt();//3个参数
for(int j=0;j<A1;j++) {//接下来皆为逻辑判断,穷举情况
if(j==0) {
int temp=z1+z2*A[j][0]+z3*A[j][1];
if(temp<0) {
flagA = false;
}
}
else {
flagA2 = true;
int temp=z1+z2*A[j][0]+z3*A[j][1];
if(temp<0) {
flagA2 = false;
}
if(flagA2!=flagA) {
res[i] = "No";
flag=false;
break;
}
}
}
if(flag) {
for(int j=0;j<B1;j++) {
if(j==0) {
int temp=z1+z2*B[j][0]+z3*B[j][1];
if(temp<0) {
flagB = false;
}
if(flagB==flagA) {
res[i] = "No";
break;
}
}
else {
flagB2 = true;
int temp=z1+z2*B[j][0]+z3*B[j][1];
if(temp<0) {
flagB2 = false;
}
if(flagB2!=flagB) {
res[i] = "No";
break;
}
}
if(j==(B1-1))
{
res[i]="Yes";
}
}
}
}
for(int i=0;i<m;i++) {
System.out.println(res[i]);
}
}
}