csp 2020-06-01 线性分类器
#include<iostream>
using namespace std;
struct node{
int x;
int y;
char type;
};
struct line{
int a;
int b;
int c;
};
int main(){
int n;
int m;
cin>>n>>m;
struct node nz[n];
struct line lz[m];
for( int i =0;i<n;i++){
cin>>nz[i].x>>nz[i].y>>nz[i].type;
}
for(int i = 0;i<m;i++){
cin>>lz[i].c>>lz[i].a>>lz[i].b;
}
for(int i=0;i<m;i++){
int flagA = 0;
int flagB = 0;
if(lz[i].a * nz[0].x + lz[i].b *nz[0].y +lz[i].c < 0 && nz[0].type =='A'
||lz[i].a * nz[0].x + lz[i].b *nz[0].y + lz[i].c > 0 && nz[0].type =='B'){
flagA = -1;
flagB = 1;
}
else{
flagB = -1;
flagA = 1;
}
bool flag =true;
for(int j =1 ;j < n;j++){
int value = lz[i].a * nz[j].x + lz[i].b *nz[j].y +lz[i].c;
if(nz[j].type =='A'){
if(value * flagA < 0)
{
flag = false;
break;
}
}
else if(nz[j].type =='B'){
if(value * flagB < 0)
{
flag = false;
break;
}
}
}
if(flag){
printf("Yes\n");
}
else {
printf("No\n");
}
}
return 0;
}