CCF--线性分类器

#include<iostream>
using namespace std;

int n = 1000;
struct point{
    int x;
    int y;
    char type;
}point;



int main(){

    int  m, x, y, theta1, theta2, theta3;
    char c;
    cin >> n >> m;
    struct point arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i].x >> arr[i].y >> arr[i].type;
    }

    for(int i = 0; i < m; i++){
        cin >> theta1 >> theta2 >> theta3;
        int flag = 1;
        int a = 0, b = 0, c = 0;
        for(int j = 0; j < n; j++){

            if(a == 0 && b == 0){
                //initiaal
                if(theta1 + theta2 * arr[j].x + theta3 * arr[j].y > 0){
                    if(arr[j].type == 'A'){
                        a = 1;
                        b = -1;
                    }else{
                        a = -1;
                        b = 1;
                    }
                }else{
                    if(arr[j].type == 'B'){
                        a = 1;
                        b = -1;
                    }else{
                        a = -1;
                        b = 1;
                    }
                }
            }else{

                c = (theta1 + theta2 * arr[j].x + theta3 * arr[j].y > 0)? 1: -1;
                if(arr[j].type == 'A' && c != a){
                    flag = 0;
                    break;
                }else if(arr[j].type == 'B' && c != b){
                    flag = 0;
                   // cout << "tihsB" << arr[j].x << arr[j].y <<endl;
                    break;
                }
            }


        }


        if(flag){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}



posted @ 2020-09-08 14:22  c_y_yuan  阅读(575)  评论(0编辑  收藏  举报