CSP 2020-06-01 线性分类器

逻辑有点混乱
#include<iostream>
using namespace std;
struct Point 
{
	int x;
	int y;
	char type;
};
struct Inquire
{
	int a;
	int b;
	int c;
};
int main() {
	int n, m;
	cin >> n >> m;
	Point * p = new Point[n];
	Inquire * quire = new Inquire[m];
	bool type1 = false;
	bool type2 = false;
	int* a = new int[n]();
	int* b = new int[n]();
	for (int i = 0; i < n; i++)
	{
		cin >> p[i].x >> p[i].y >> p[i].type;
	}
	for (int j = 0; j < m; j++)
	{
		cin >> quire[j].c >> quire[j].a >> quire[j].b;
	}
	for (int i = 0; i < m; i++) {
		
		for (int j = 0; j < n; j++) {
			int result = quire[i].a * p[j].x + quire[i].b * p[j].y + quire[i].c;
			if (p[j].type == 'A') {
				if (result > 0)
					a[j] = 2;
				else if (result < 0) {
					a[j] = 1;
				}
			}
			else if (p[j].type == 'B') {
				if (result > 0)
					b[j] = 2;
				else if (result < 0) {
					b[j] = 1;
				}
			}
		}
		int typeA = 0;
		int typeB = 0;
		for (int k = 0; k < n; k++) {
			if (a[k] != 0) {
				if (typeA == 0) {
					typeA = a[k];
					type1 = true;
				}
				else {
					if (typeA == a[k])
						type1 = true;
					else {
						type1 = false;
						break;
					}
				}	
			}
		}
		for (int k = 0; k < n; k++) {
			if (b[k] != 0) {
				if (typeB == 0) {
					typeB = b[k];
					type2 = true;
				}
				else {
					if (typeB == b[k])
						type2 = true;
					else {
						type2 = false;
						break;
					}
				}
			}
		}
		if (type1 == true && type2 == true)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
csp线性分类器是一个用于将二维平面上的点分为A类和B类的分类器。它通过训练数据中的点的坐标和类别来确定一条直线作为分类器,使得直线将A类点和B类点完美分隔开来。给定直线的参数可以通过输入给定的查询进行判断,如果给定直线可以完美分隔A类和B类点,则输出"Yes",否则输出"No"。 在Python中,可以使用多种方法实现csp线性分类器。例如,可以使用列表和循环来读取输入数据,并使用条件语句来判断直线是否可以完美分隔点。具体的实现代码可以参考引用和引用中的示例代码。 需要注意的是,实现csp线性分类器的关键在于判断直线是否能够将A类和B类点完美分隔。可以根据直线方程来计算点与直线的关系,如果对于所有的点,点与直线的乘积符号相同,则直线可以完美分隔点。否则,直线不能完美分隔点。 希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [CSP202006-1 线性分类器 (Python)](https://blog.csdn.net/qq_45899597/article/details/113716943)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [CSP 202006-1 线性分类器 python](https://blog.csdn.net/weixin_45508265/article/details/121438786)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值