CCF 202006-1 线性分类器

#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

typedef struct
{
    int x;int y;char type;
}XY;

vector<XY> xy;
int theta0,theta1,theta2;
bool AorB;

bool topOrbelow(XY user)
{
    if(theta0+theta1*user.x+theta2*user.y>0)
        return true;
    else
        return false;
}

int main()
{
    int n,m;
    cin>>n>>m;
    XY temp;
    while(n--)
    {
        cin>>temp.x>>temp.y>>temp.type;
        xy.push_back(temp);
    }
    while(m--)
    {
        bool flag=true,flag0=false;
        cin>>theta0>>theta1>>theta2;
        for(int i=0;i<xy.size();i++)
        {
            if(i==0)
            {
                if(xy[i].type=='A')
                {
                    if(topOrbelow(xy[i]))
                    flag0=true; //上分为A类
                }
                else
                {
                    if(!topOrbelow(xy[i]))
                    flag0=true;
                }
            }
            if(flag0)
            {
                if(!((topOrbelow(xy[i])&&xy[i].type=='A')||(!topOrbelow(xy[i])&&xy[i].type=='B')))
                {
                    flag=false;
                    break;
                }
            }
            else
            {
                if(!((topOrbelow(xy[i])&&xy[i].type=='B')||(!topOrbelow(xy[i])&&xy[i].type=='A')))
                {
                    flag=false;
                    break;
                }
            }
        }
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}
原文地址:https://www.cnblogs.com/-Asurada-/p/14367687.html