题目
解题思路-初
题目太长了,的确发现近些年来1,2题跟后面几题一样罗里吧嗦的。其实就是判断给定直线能否将给定的两种类型的点刚好分隔开。那也就是初高中学的,假如
直线为a + bx + cy = 0
坐标为 (x0,y0)
- 当 a + bx0 + cy0 > 0 时 点在直线的一边
- 当 a + bx0 + cy0 < 0 时 点在直线的另一边
- 当 a + bx0 + cy0 = 0 时 点在直线上
AC代码c++11
#include <iostream>
#include <stack>
using namespace std;
struct line{
int a;
int b;
int c;
};
int main() {
int x,y;
char type;
int n,m;
int q,w,e;
int sumA = 0 , sumB = 0;
cin>>n>>m;
//a,b存A类
int a[1001] = {
0};
int b[1001] = {
0};
int c[1001] = {
0};
int d[1001] = {
0};
line l[1001] ;
for(int i = 0; i < n ; i++){
cin>>x>>y>>type;
if(type == 'A') {
a[sumA] = x;
b[sumA] = y;
sumA++;
}
else{
c[sumB] = x;
d[sumB] = y;
sumB++;
}
}
for(int i = 0; i < m; i++){
cin>>q>>w>>e;
l[i].a = q;
l[i].b = w;
l[i].c = e;
}
for(int i = 0; i < m; i++){
//cont代表有多少点不符合
int cont1 = 0;//表示A类点不在目标线的上部分的个数
int cont2 = 0;
int cont3 = 0;
int cont4 = 0;
for(int j = 0; j < sumA; j++){
//cout<<l[i].a + l[i].b*a[j] + l[i].c*b[j]<<endl;
if(l[i].a + l[i].b*a[j] + l[i].c*b[j] <= 0)
cont1++;