【CCF】线性分类器

在这里插入图片描述
【样例1输入】

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

【样例1输出】

No
No
Yes
数学问题。就看是在直线上方还是下方
#include <iostream>
using namespace std;

const int N = 1010;
typedef long long ll;

struct Line {
    int x, y, type;
} line[N];

int n, m, a, b, c;

bool gt(ll x, ll y) {
    return a + b * x + c * y > 0;
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) 
        scanf("%d %d %c", &line[i].x, &line[i].y, &line[i].type);
    for (int i = 0; i < m; i++) {
        scanf("%d %d %d", &a, &b, &c);
        if (n == 1) {
            printf("Yes\n");
            continue;
        }
        bool flag = gt(ll(line[0].x), ll(line[0].y));
        char ch = line[0].type;
        int j;
        for (j = 1; j < n; j++) {
            if (ch == line[j].type) {
                bool res = gt(ll(line[j].x), ll(line[j].y));
                if (res != flag) break; // 不符合
            } else {
                bool res = gt(ll(line[j].x), ll(line[j].y));
                if (res == flag) break; // 不符合
            }
        }
        if (j == n) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值