import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
class Point{
int x;
int y;
String type;
Point(int x, int y, String type){
this.x = x;
this.y = y;
this.type = type;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "(" + this.x + "," + this.y + "," + this.type + ")";
}
}
class Line{
int a;
int b;
int c;
Line(int a, int b, int c){
this.a = a;
this.b = b;
this.c = c;
}
@Override
public String toString() {
return "Line [a=" + a + ", b=" + b + ", c=" + c + "]";
}
}
public class LinearClassifier {
public static void main(String[] args) throws IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String str = input.readLine().trim();
String[] arr = str.split(" ");
int n = Integer.valueOf(arr[0]);
int m = Integer.valueOf(arr[1]);
// 输入n个点
List<Point> points = new ArrayList<>();
for(int i = 0; i < n; ++i) {
str = input.readLine().trim();
arr = str.split(" ");
points.add(new Point(Integer.valueOf(arr[0]),
Integer.valueOf(arr[1]), arr[2]));
}
List<Line> lines = new ArrayList<Line>();
for(int i = 0; i < m; ++i) {
str = input.readLine().trim();
arr = str.split(" ");
lines.add(new Line(Integer.valueOf(arr[0]),
Integer.valueOf(arr[1]), Integer.valueOf(arr[2])));
}
List<String> ans = new ArrayList<String>();
for(Line temp_l: lines) {
boolean flag = (temp_l.a + temp_l.b * points.get(0).x + temp_l.c * points.get(0).y) > 0;
String type = points.get(0).type;
boolean check_flag = true;
for(int i = 1; i < n; ++i) {
boolean tmp_flag = (temp_l.a + temp_l.b * points.get(i).x + temp_l.c * points.get(i).y) > 0;
if((!points.get(i).type.equals(type) && tmp_flag != flag)
|| (points.get(i).type.equals(type) && tmp_flag == flag)) {
continue;
}
check_flag = false;
break;
}
if(!check_flag) {
ans.add("No");
}else {
ans.add("Yes");
}
}
for(int i = 0; i < m; ++i) {
System.out.println(ans.get(i));
}
}
}
ccf_线性分类器
最新推荐文章于 2022-08-18 19:30:34 发布