csp 202006-1 线性分类器
作者:互联网
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct Point{
int x;
int y;
}pointA[1005],pointB[1005];
int main(){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
int xcount=1;
int ycount=1;
for(int i=1;i<=n;i++){
string type;
int xtemp,ytemp;
cin>>xtemp>>ytemp>>type;
if(type == "A"){
pointA[xcount].x=xtemp;
pointA[xcount].y=ytemp;
xcount++;
}else if(type == "B"){
pointB[ycount].x=xtemp;
pointB[ycount].y=ytemp;
ycount++;
}
}
int flag[m]={0};
for(int j=1;j<=m;j++){
int t0,t1,t2;
cin>>t0>>t1>>t2;
int resultA =t0+t1*pointA[1].x+t2*pointA[1].y;
int resultB =t0+t1*pointB[1].x+t2*pointB[1].y;
for(int i=2;i<xcount;i++){
int resA =t0+t1*pointA[i].x+t2*pointA[i].y;
if(resA>0&&resultA<0||resA<0&&resultA>0){
flag[j]=1;
break;
}
}
for(int i=2;i<ycount;i++){
int resB =t0+t1*pointB[i].x+t2*pointB[i].y;
if(resB<0&&resultB>0||resB>0&&resultB<0){
flag[j]=1;
break;
}
}
}
for(int i=1;i<=m;i++){
if(flag[i]==1){
cout<<"No"<<endl;
}
else
cout<<"Yes"<<endl;
}
}
写在最后:
该博客是本人学习的一些总结,如果各位有不同见解,可以评论提出或者与我联系改正,谢谢阅览!!
标签:202006,pointB,pointA,int,xcount,分类器,ycount,type,csp 来源: https://blog.csdn.net/qq_45830251/article/details/121719906