试题编号 | 202006-1 |
---|
试题名称 | 线性分类器 |
时间限制 | 1.0s |
内存限制 | 512.0MB |
问题描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e6931e654613754cfb64fd5017be37b6.png#pic_center)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3aa35efca470cff9c1fbf6dfe0337d1f.png#pic_center)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0aaf90e8b4053ed17696bef41d1e0ca0.png#pic_center)
实现代码
#include<iostream>
#include<string>
using namespace std;
const int maxn = 1e3 + 5;
int buff, n, m;
char type;
struct Point{
int x, y;
char type;
Point() {}
Point(int x, int y, char t) : x(x), y(y), type(t){}
}point[maxn];
bool judge(int a, int b, int c) {
buff = (a + b * point[0].x + c * point[0].y);
if (buff == 0) return false;
buff = buff > 0 ? 1 : 0;
for (int i = 1; i < n; i++) {
int nowbuff = (a + b * point[i].x + c * point[i].y);
if (nowbuff == 0) return false;
nowbuff = nowbuff > 0 ? 1 : 0;
if (point[i].type == type && buff != nowbuff) return false;
if (point[i].type != type && buff == nowbuff) return false;
}
return true;
}
int main() {
int x, y, a, b, c;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> x >> y >> type;
point[i] = Point(x, y, type);
}
type = point[0].type;
while (m--) {
cin >> a >> b >> c;
cout << (judge(a, b, c) ? "Yes" : "No") << endl;
}
return 0;
}