CSP202006-1

试题名称:

线性分类器

时间限制:

1.0s

内存限制:

512.0MB

问题描述: 在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

C++

#include<iostream>
using namespace std;


class Point
{
    public:
        int x;
        int y;
        char type;
};

int main()
{
    int n, m;
    cin >> n >> m;

    Point typeA[1005], typeB[1005];

    int x, y;
    char type;
    int i1 = 0, i2 = 0;
    for(int i = 0; i < n; ++i)
    {
        cin >> x >> y >> type;
        if(type == 'A')
        {
            typeA[i1].x = x;
            typeA[i1].y = y;
            i1++;
        }
        else
        {
            typeB[i2].x = x;
            typeB[i2].y = y;
            i2++;
        }
    }

    int o0, o1, o2;
    int ans[m];
    for(int j = 0; j < m; ++j)
    {
        cin >> o0 >> o1 >> o2;
        if(o0 + o1 * typeA[0].x + o2 * typeA[0].y > 0)
        {
            int res = 1;
            for(int k = 0; k < i1; ++k)
            {
                if(o0 + o1 * typeA[k].x + o2 * typeA[k].y < 0)
                {
                    ans[j] = 0;
                    res = 0;
                    break;
                }
            }
            for(int k = 0; k < i2; ++k)
            {
                if(o0 + o1 * typeB[k].x + o2 * typeB[k].y > 0)
                {
                    ans[j] = 0;
                    res = 0;
                    break;
                }
            }
            if(res == 1)
                ans[j] = 1;
        }



        if(o0 + o1 * typeA[0].x + o2 * typeA[0].y < 0)
        {
            int res = 1;
            for(int k = 0; k < i1; ++k)
            {
                if(o0 + o1 * typeA[k].x + o2 * typeA[k].y > 0)
                {
                    ans[j] = 0;
                    res = 0;
                    break;
                }
            }
            for(int k = 0; k < i2; ++k)
            {
                if(o0 + o1 * typeB[k].x + o2 * typeB[k].y < 0)
                {
                    ans[j] = 0;
                    res = 0;
                    break;
                }
            }
            if(res == 1)
                ans[j] = 1;
        }
    }
    for(int i  = 0; i < m; ++i)
    {
        if(ans[i] == 0)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
    return 0;
}

posted @ 2021-08-31 15:08  子丶非鱼Zzz  阅读(58)  评论(0)    收藏  举报