【CCF】202006-1-线性分类器(c++)

【CCF】202006-1-线性分类器(c++)

代码长度		1.968KB
编程语言		C++
评测结果		正确
得分			100
时间使用		15ms
空间使用		2.906MB						
#include<iostream>
using namespace std;
#include<vector>
#include<string>

struct Lsort {
	int m_x;
	int m_y;
}A[100000], B[100000];

void printStr(string res) {
	int len;
	len = sizeof(res);
	for (string::iterator it = res.begin(); it != res.end(); it++) {
		cout << *it << endl;
	}
}

void test()
{
	string res[50];
	int n = 0, m = 0;
	cin >> n;
	cin >> m;

	//获取数据
	int a_count = 0, b_count = 0;

	for (int i = 0; i < n; i++) {
		int a = 0, b = 0;
		char c = ' ';
		cin >> a;
		cin >> b;
		cin >> c;

		//写入数组中
		if (c == 'A') {
			int a_k;
			a_count = a_count + 1;
			a_k = a_count - 1;
			A[a_k].m_x = a;
			A[a_k].m_y = b;
		}
		if (c == 'B') {
			int b_k;
			b_count = b_count + 1;
			b_k = b_count - 1;
			B[b_k].m_x = a;
			B[b_k].m_y = b;
		}
	}

	//cout << "A len : " << a_count << endl;
	//cout << "B len : " << b_count << endl;

	//处理数据

	int q = 0;

	for (int i = 0; i < m; i++) {

		int ad = 0, ax = 0, bd = 0, bx = 0;
		int a1 = 0, a2 = 0, a3 = 0;
		cin >> a1;
		cin >> a2;
		cin >> a3;
		for (int j = 0; j < a_count; j++) {
			int a_res = 0;
			a_res = a1 + a2 * A[j].m_x + a3 * A[j].m_y;
			//a在上的个数
			if (a_res > 0) {
				ad++;
			}
			//a在下的个数
			if (a_res < 0) {
				ax++;
			}
		}
		for (int j = 0; j < b_count; j++) {
			int b_res = 0;
			b_res = a1 + a2 * B[j].m_x + a3 * B[j].m_y;
			//b在上的个数
			if (b_res > 0) {
				bd++;
			}
			//b在下的个数
			if (b_res < 0) {
				bx++;
			}
		}

		//cout << "as: " << ad << "  ax: " << ax << endl;
		//cout << "bs: " << bd << "  bx: " << bx << endl;

		//进行比较
		if (a_count == ad && b_count == bx || a_count == ax  && b_count == bd) {
			//cout << "Yes" << endl;
			res[q] = "Yes";
		}
		//if(a_count != ad || b_count != bx || a_count != ax || b_count != bd) {
		//	cout << "No" << endl;
		//}
		else {
			//cout << "No" << endl;

			res[q] = "No";
		}

		q++;

	}

	//打印输出
	for (int i = 0; i < m; i++) {
		cout << res[i] << endl;
	}


}

int main()
{
	test();
	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
*/

//核心思想
//#include<iostream>
//using namespace std;
//
//int main()
//{
//	int count1 = 0, count2 = 0;
//	int a = 0, b = 0, n = 0;
//	cin >> n;
//	for (int i = 0; i < n; i++) {
//		cin >> a;
//		cin >> b;
//		if (a > 0 && b < 0 || a < 0 && b>0) {
//			count1++;
//		}
//		else {
//			count2++;
//		}
//	}
//
//	cout << "count1: " << count1 << endl;
//	cout << "count2: " << count2 << endl;
//
//	return 0;
//	
//}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值