其他分享
首页 > 其他分享> > CSP_202006-1_线性分类器

CSP_202006-1_线性分类器

作者:互联网

题目描述

#include <iostream>
#include <vector>
#include <set> 
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstring>
using namespace std;

const int INF = 0x3f3f3f3f;

int main() {
	int n, query_times;
	vector<pair<int,int>> points; // {<x,y>, <x,y>}
	vector<char> type;
	bool a_above; // > 0
	
	cin >> n >> query_times;
	for (int i = 0; i < n; i++) {
		int x, y;
		char c;
		cin >> x >> y;
		cin >> c;
		auto pair = make_pair(x,y);
		points.push_back(pair);
		type.push_back(c);
	}
	for (int i = 0; i < query_times; i++) {
		int a, b, c; // a + bx + cy 
		cin >> a >> b >> c;
		int w = a + b * points[0].first + c * points[0].second;
		if (type[0] == 'A') {
			a_above = (w > 0);
		} else {
			a_above = !(w > 0);
		}
		bool flag = true;
		for (int j = 0; j < n; j++) {
			w = a + b * points[j].first + c * points[j].second;
			bool above = (w>0);
			if (type[j] == 'A' && above != a_above) {
				flag = false;
				break;
			} else if (type[j] == 'B' && above != !(a_above)){
				flag = false;
				break;
			} else {
				// pass
			}
		}
		if (flag) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

标签:202006,int,分类器,flag,points,above,include,type,CSP
来源: https://www.cnblogs.com/ticlab/p/15642618.html