当前位置: 移动技术网 > 科技>办公>内存 > CSP202006-1 线性分类器【数学】

CSP202006-1 线性分类器【数学】

2020年09月01日  | 移动技术网科技  | 我要评论
试题编号:202006-1试题名称:线性分类器时间限制:1.0s内存限制:512.0MB问题链接:CSP202006-1 线性分类器问题简述:(略)问题分析:判定点集合是否都在同一侧,可以将点代入解析式,如果都>0或都<0则在同一侧。程序说明:(略)参考链接:(略)题记:(略)AC的C++语言程序如下:/* CSP202006-1 线性分类器 */#include <bits/stdc++.h>using namespace std;c

试题编号: 202006-1
试题名称:
时间限制: 1.0s
内存限制: 512.0MB
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
问题链接
问题简述:(略)
问题分析:判定点集合是否都在同一侧,可以将点代入解析式,如果都>0或都<0则在同一侧。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* CSP202006-1 线性分类器 */

#include <bits/stdc++.h>

using namespace std;

const int N = 1000;
struct Point {
    int x, y;
} a[N], b[N];
int acnt, bcnt;

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    acnt = bcnt = 0;
    for(int i = 0; i < n; i++) {
        int x, y;
        char type2[2];

        scanf("%d%d%s", &x, &y, type2);
        if(type2[0] == 'A') {
            a[acnt].x = x;
            a[acnt++].y = y;
        } else if(type2[0] == 'B') {
            b[bcnt].x = x;
            b[bcnt++].y = y;
        }
    }

    for(int i = 1; i <= m; i++) {
        bool side, ans = true;
        int t0, t1, t2;
        scanf("%d%d%d", &t0, &t1, &t2);
        if(acnt)
            side = t0 + a[0].x * t1 + a[0].y * t2 > 0;
        else
            side = t0 + b[0].x * t1 + b[0].y * t2 > 0;

        // 判定A点集合是否在同一侧
        for(int i = 1; i < acnt; i++)
            if(t0 + a[i].x * t1 + a[i].y * t2 > 0 != side) {
                ans = false;
                break;
            }

        // 判定B点集合是否在同一侧
        if(ans) {
            for(int i = 0; i < bcnt; i++)
                if(t0 + b[i].x * t1 + b[i].y * t2 > 0 == side) {
                    ans = false;
                    break;
                }
        }

        printf(ans ? "Yes\n" : "No\n");
    }

    return 0;
}

本文地址:https://blog.csdn.net/tigerisland45/article/details/108571300

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网