CCF/CSP 202006-1 线性分类器

CCF/CSP 202006-1 线性分类器

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define _for(i, a, b) for(int i = a; i <= b; i++)

using namespace std;

int aA[3];
int aB[3];
const int N = 1e+3;
struct Node {
	int x;
	int y;
	char type;
} node[N + 10];

int main() {
//	freopen("in.txt", "r", stdin);
	int n, m;
	cin >> n >> m;

	_for(i, 1, n) {
		scanf("%d%d %c", &node[i].x, &node[i].y, &node[i].type);  // %c前面添加空格的原因,见后文
	}
	_for(i, 1, m) {
		memset(aA, 0, sizeof(aA));
		memset(aB, 0, sizeof(aB));
		int p0, px, py;
		scanf("%d%d%d", &p0, &px, &py);

		_for(j, 1, n) {
			int tmp = p0 + node[j].x * px + node[j].y * py;
//			cout << node[j].type[0] << endl;

			if (node[j].type == 'A') {
				if (tmp < 0)
					aA[0]++;
				else
					aA[1]++;
			} else if (node[j].type == 'B') {
				if (tmp < 0)
					aB[0]++;
				else
					aB[1]++;
			}
		}

		if ((aA[0] > 0 && aA[1] > 0) || (aB[0] > 0 && aB[1] > 0)) {  // 除去同一区域的不满足的情况
			cout << "No" << endl;
		} else {
			if ((aA[1] > 0 && aB[0] > 0) || (aA[0] > 0 && aB[1] > 0))  // 求出不同区域满足条件的情况
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		}
	}

	return 0;
}

scanf()函数的%c格式符输入字符型数据时存在的问题:空格和转义字符(包括回车)都会被当作有效字符读入,前面加一个空格是限定输入数据的格式,前两个整数%d%d默认空格分隔,后面输入字符时,必须按照指定的格式:即先输入一个空格,再输入字符。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值