题目
![]() ![]() ![]() |
---|
思路
判定点集合是否都在同一侧,可以将点代入解析式,如果都>0或都<0则在同一侧。
坑
….逻辑不难,但TM的要注意,标准输出是‘Yes’,不是’YES’!!害得我一直错!!
代码
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
struct point{
int x,y;
char type;
};
struct line{
int theta0,theta1,theta2;
};
vector<point> points;
line lines[21];
int count_A=0,count_B=0;
int main(){
memset(lines,0,sizeof(line));//初始化数组
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
point temp_point;
cin>>temp_point.x>>temp_point.y>>temp_point.type;
if(temp_point.type =='A'){
count_A++;
}else{
count_B++;
}
points.push_back(temp_point);
}
for(int j=0;j<m;j++){
line temp_line;
cin>>temp_line.theta0>>temp_line.theta1>>temp_line.theta2;
lines[j] =temp_line;
}
for(int j=0;j<m;j++){
int A1=0,A0=0,B1=0,B0=0;
for(int i=0;i<n;i++){
int result =lines[j].theta0+lines[j].theta1*points[i].x+lines[j].theta2*points[i].y;
if(points[i].type =='A'){
if(result>=0){
A1++;
}else{
A0++;
}
//continue;
} else if(points[i].type =='B'){
if(result>=0){
B1++;
}else{
B0++;
}
//continue;
}
}
if(A0==count_A&&B1==count_B){
//A全小于0,B全大于0
cout<<"Yes"<<endl;
continue;
}
if(A1==count_A&&B0==count_B){
//A全大于0,B全小于0
cout<<"Yes"<<endl;
continue;
}
cout<<"No"<<endl;
}
return 0;
}