202006-1 |
线性分类器-----Java版
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int[] a=new int[n];
int[] b=new int[n];
char[] c=new char[n];
int d=0,e=0,f=0,g=0;
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
b[i]=sc.nextInt();
c[i]=sc.next().charAt(0);
}
for(int j=0;j<m;j++) {
int aa=sc.nextInt();
int bb=sc.nextInt();
int cc=sc.nextInt();
d=0;e=0;f=0;g=0;
for(int i=0;i<n;i++) {
if(c[i]=='A') {
if(aa+bb*a[i]+cc*b[i]<0) {
d++;
}
if(aa+bb*a[i]+cc*b[i]>0) {
e++;
}
}
if(c[i]=='B') {
if(aa+bb*a[i]+cc*b[i]>0) {
f++;
}
if(aa+bb*a[i]+cc*b[i]<0) {
g++;
}
}
}
if(e==0&&g==0||d+e==e&&f+g==g) {
System.out.println("Yes");
}
else
System.out.println("No");
}
}
}