C++实现CCF的202006-1线性分类器

题目地址:http://118.190.20.162/view.page?gpid=T105

代码如下

#include <bits/stdc++.h>

using namespace std;
int main(){
	int m,n;
	cin>>n>>m;
	vector<int> x;
	vector<int> y;
	vector<char> c;
	// 获取坐标点
	for(int i=0;i<n;++i){
		int x_i,y_i;
		char c_i;
		cin>>x_i>>y_i>>c_i;
		x.push_back(x_i);
		y.push_back(y_i);
		c.push_back(c_i);
	}
	// 获取指定的  theta,theta1,theta2
	for(int i=0;i<m;++i){
		int theta,theta1,theta2;
		cin >> theta >> theta1 >> theta2;
		int a=0,b=0;
		for(int j=0;j<n;++j){
			// 如果type是A
			if(c[j] == 'A')
				theta+theta1*x[j]+theta2*y[j]>0?a++:a--;
			else
				theta+theta1*x[j]+theta2*y[j]>0?b++:b--;
		}
		if( (count(c.begin(),c.end(),'A')==abs(a)) && (count(c.begin(),c.end(),'B')==abs(b)) )
			cout <<  "Yes" << endl;
		else
			cout << "No" << endl;
	}
    return 0;
}
posted @ 2020-08-14 11:41  Adam_lxd  阅读(418)  评论(0编辑  收藏  举报