【练习记录】202006-1 线性分类器

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, m, x, y, a, b, c;
char l;
vector<vector<int>> point, point2;
vector<int> res;
int flag, flag2, resFlag = 1;
int main() {
	while (cin >> n) {
		cin >> m;
		while (n--) {
			cin >> x >> y >> l;
			vector<int> t;
			t.push_back(x);
			t.push_back(y);
			if (l == 'A') point.push_back(t);
			else point2.push_back(t);
		}
		break;
	}

	while (m--) {
		cin >> a >> b >> c;
		flag = ((a + b * point[0][0] + c * point[0][1]) > 0) ? 1 : 0;
		flag2 = ((a + b * point2[0][0] + c * point2[0][1]) > 0) ? 1 : 0;
		if (flag == flag2) {
			resFlag = 0;
		}
		if (resFlag == 1) {
			for (int i = 1; i < point.size(); i++) {
				if (((a + b * point[i][0] + c * point[i][1]) > 0) == flag);
				else {
					resFlag = 0;
					break;
				}
			}
		}
		if (resFlag == 1) {
			for (int i = 1; i < point2.size(); i++) {
				if (((a + b * point2[i][0] + c * point2[i][1]) > 0) == flag2);
				else {
					resFlag = 0;
					break;
				}
			}
		}
		res.push_back(resFlag);
		resFlag = 1;
	}

	for (int i = 0; i < res.size(); i++) {
		cout << ((res[i] > 0) ? "Yes" : "No") << endl;;
	}
	return 0;
}

/*
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
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值