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() {
int n, m;
cin >> n >> m;
_for(i, 1, n) {
scanf("%d%d %c", &node[i].x, &node[i].y, &node[i].type);
}
_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;
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
默认空格分隔,后面输入字符时,必须按照指定的格式:即先输入一个空格,再输入字符。