csp 202006-1 线性分类器
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cstdio>
using namespace std;
struct Station{
int xi;
int yi;
char typei;
};
struct Line{
int o1;
int o2;
int o3;
bool ty;//存放a+b*x+c*y>0的类别
bool ans;
};
int main(){
int n,m,i,h,j;char c;
scanf("%d%d",&n,&m);Station a[n];Line b[m];
for(i=0;i<n;i++){
scanf("%d %d %c",&a[i].xi,&a[i].yi,&a[i].typei);
}
for(i=0;i<m;i++){
scanf("%d %d %d",&b[i].o1,&b[i].o2,&b[i].o3);b[i].ans=1;
b[i].ty=b[i].o1+b[i].o2*a[0].xi+b[i].o3*a[0].yi>0?0:1;
c=a[0].typei;
for(j=1;j<n;j++){
h=b[i].o1+b[i].o2*a[j].xi+b[i].o3*a[j].yi;
//printf("%d %d %d %d %d %d %d\n",j,h,b[i].o1,b[i].o2,a[j].xi,b[i].o3,a[j].yi);
if(b[i].ty==0){
if(h>0&&a[j].typei!=c){b[i].ans=0;}
else if(h<0&&a[j].typei==c){b[i].ans=0;}
}
else{
if(h<0&&a[j].typei!=c){b[i].ans=0;}
else if(h>0&&a[j].typei==c){b[i].ans=0;}
}
}
}
for(i=0;i<m;i++){
if(b[i].ans==0)printf("No\n");
else printf("Yes\n");
}
return 0;
}
测试样例;
9 3
1 1 A
1 0 A
1 -1 A
2 2 B
2 3 B
0 1 A
3 1 B
1 3 B
2 0 A
0 2 -3
-3 0 2
-3 1 1